public void DataBindEvents(Grid grid, DataViewBase dataView, string gridContainerDivId) { // Data Sorting grid.OnSort.Subscribe(delegate(EventData o, Object item) { SortColData sorting = (SortColData)item; dataView.Sort(sorting); grid.Invalidate(); grid.Render(); }); // Session Grid DataBinding grid.OnAddNewRow.Subscribe(delegate(EventData o, Object item) { EditEventData data = (EditEventData)item; dataView.AddItem(data.item); Column column = data.column; grid.InvalidateRow(dataView.GetLength() - 1); grid.UpdateRowCount(); grid.Render(); }); dataView.OnRowsChanged.Subscribe(delegate(EventData e, object a) { OnRowsChangedEventArgs args = (OnRowsChangedEventArgs)a; if (args != null && args.Rows != null) { grid.InvalidateRows(args.Rows); grid.Render(); } else { // Assume that a new row has been added grid.InvalidateRow(dataView.GetLength()); grid.UpdateRowCount(); grid.Render(); } grid.ResizeCanvas(); }); jQueryObject loadingIndicator = null; // Wire up the validation error jQueryObject validationIndicator = null; Action <EventData, object> clearValidationIndicator = delegate(EventData e, object a) { if (validationIndicator != null) { validationIndicator.Hide(); validationIndicator.Remove(); } }; grid.OnCellChange.Subscribe(clearValidationIndicator); grid.OnActiveCellChanged.Subscribe(clearValidationIndicator); grid.OnBeforeCellEditorDestroy.Subscribe(clearValidationIndicator); grid.OnValidationError.Subscribe(delegate(EventData e, object a) { ValidationEventArgs args = (ValidationEventArgs)a; ValidationResult validationResult = (ValidationResult)args.ValidationResults; jQueryObject activeCellNode = (jQueryObject)args.CellNode; object editor = args.Editor; string errorMessage = ""; if (validationResult.Message != null) { errorMessage = validationResult.Message; } bool valid_result = validationResult.Valid; // Add the message to the tooltip on the cell if (!valid_result) { jQuery.FromObject(activeCellNode).Attribute("title", errorMessage); clearValidationIndicator(e, a); validationIndicator = jQuery.FromHtml("<div class='popup-box-container'><div width='16px' height='16px' class='sparkle-imagestrip-inlineedit_warning popup-box-icon' alt='Error' id='icon'/><div class='popup-box validation-text'/></div>").AppendTo(Document.Body); validationIndicator.Find(".validation-text").Text(errorMessage); string colisionPosition = ValidationPopupUseFitPosition ? "fit fit" : "none none"; Script.Literal(@"{0}.position({{ my: 'left bottom', at: 'left top', collision: '{2}', of: {1} }}) .show({{ effect: 'blind' }}) .delay( 500000 ) .hide({{ effect: 'fade', duration: 'slow', }}, function() {{ $( this ).remove(); }}); ", validationIndicator, activeCellNode, colisionPosition); } else { clearValidationIndicator(e, a); jQuery.FromObject(activeCellNode).Attribute("title", ""); } }); // Wire up the loading spinner dataView.OnDataLoading.Subscribe(delegate(EventData e, object a) { loadingIndicator = ShowLoadingIndicator(loadingIndicator, gridContainerDivId); foreach (Column col in grid.GetColumns()) { if (col.MaxWidth != null) { col.MaxWidth = 400; } } }); dataView.OnDataLoaded.Subscribe(delegate(EventData e, object a) { DataLoadedNotifyEventArgs args = (DataLoadedNotifyEventArgs)a; if (args != null) { if (args.ErrorMessage == null) { for (int i = args.From; i <= args.To; i++) { grid.InvalidateRow(i); } grid.UpdateRowCount(); grid.Render(); } else { Script.Alert("There was a problem refreshing the grid.\nPlease contact your system administrator:\n" + args.ErrorMessage); } } if (loadingIndicator != null) { loadingIndicator.Plugin <jQueryBlockUI>().Unblock(); } }); // Wire up edit complete to property changed grid.OnCellChange.Subscribe(delegate(EventData e, object data) { OnCellChangedEventData eventData = (OnCellChangedEventData)data; dataView.RaisePropertyChanged(""); }); }
public void DataBindEvents(Grid grid,DataViewBase dataView,string gridContainerDivId) { // Data Sorting grid.OnSort.Subscribe(delegate(EventData o, Object item) { SortColData sorting = (SortColData)item; dataView.Sort(sorting); grid.Invalidate(); grid.Render(); }); // Session Grid DataBinding grid.OnAddNewRow.Subscribe(delegate(EventData o, Object item) { EditEventData data = (EditEventData)item; dataView.AddItem(data.item); Column column = data.column; grid.InvalidateRow(dataView.GetLength() - 1); grid.UpdateRowCount(); grid.Render(); }); dataView.OnRowsChanged.Subscribe(delegate(EventData e, object a) { OnRowsChangedEventArgs args = (OnRowsChangedEventArgs)a; if (args != null && args.Rows != null) { grid.InvalidateRows(args.Rows); grid.Render(); } else { // Assume that a new row has been added grid.InvalidateRow(dataView.GetLength()); grid.UpdateRowCount(); grid.Render(); } }); jQueryObject loadingIndicator = null; // Wire up the validation error jQueryObject validationIndicator = null; Action<EventData, object> clearValidationIndicator = delegate(EventData e, object a) { if (validationIndicator != null) { validationIndicator.Hide(); validationIndicator.Remove(); } }; grid.OnCellChange.Subscribe(clearValidationIndicator); grid.OnActiveCellChanged.Subscribe(clearValidationIndicator); grid.OnBeforeCellEditorDestroy.Subscribe(clearValidationIndicator); grid.OnValidationError.Subscribe(delegate(EventData e, object a) { ValidationEventArgs args = (ValidationEventArgs)a; ValidationResult validationResult = (ValidationResult)args.ValidationResults; jQueryObject activeCellNode = (jQueryObject)args.CellNode; object editor = args.Editor; string errorMessage = ""; if (validationResult.Message != null) errorMessage = validationResult.Message; bool valid_result = validationResult.Valid; // Add the message to the tooltip on the cell if (!valid_result) { jQuery.FromObject(activeCellNode).Attribute("title", errorMessage); clearValidationIndicator(e,a); validationIndicator = jQuery.FromHtml("<div class='popup-box-container'><div width='16px' height='16px' class='sparkle-imagestrip-inlineedit_warning popup-box-icon' alt='Error' id='icon'/><div class='popup-box validation-text'/></div>").AppendTo(Document.Body); validationIndicator.Find(".validation-text").Text(errorMessage); Script.Literal(@"{0}.position({{ my: 'left bottom', at: 'left top', collision: 'fit fit', of: {1} }}) .show({{ effect: 'blind' }}) .delay( 500000 ) .hide({{ effect: 'fade', duration: 'slow', }}, function() {{ $( this ).remove(); }}); ", validationIndicator, activeCellNode); } else { clearValidationIndicator(e, a); jQuery.FromObject(activeCellNode).Attribute("title", ""); } }); // Wire up the loading spinner dataView.OnDataLoading.Subscribe(delegate(EventData e, object a) { loadingIndicator = ShowLoadingIndicator(loadingIndicator, gridContainerDivId); foreach (Column col in grid.GetColumns()) { if (col.MaxWidth != null) col.MaxWidth = 400; } }); dataView.OnDataLoaded.Subscribe(delegate(EventData e, object a) { DataLoadedNotifyEventArgs args = (DataLoadedNotifyEventArgs)a; if (args.ErrorMessage == null) { for (int i = args.From; i <= args.To; i++) { grid.InvalidateRow(i); } grid.UpdateRowCount(); grid.Render(); } else Script.Alert("There was a problem refreshing the grid.\nPlease contact your system administrator:\n" + args.ErrorMessage); if (loadingIndicator != null) loadingIndicator.Plugin<jQueryBlockUI>().Unblock(); }); // Wire up edit complete to property changed grid.OnCellChange.Subscribe(delegate(EventData e, object data) { OnCellChangedEventData eventData = (OnCellChangedEventData)data; dataView.RaisePropertyChanged(""); }); }