public override void Refresh() { if (_suspend) { return; } // Flattern groups List <object> rows = new List <object>(); FlatternGroups(rows, null, null, 0); _rows = rows; // Get the rows to invalidate OnRowsChangedEventArgs args = new OnRowsChangedEventArgs(); args.Rows = new List <int>(); int?startDiffRow = _refreshRowsAfter != null ?_refreshRowsAfter : 0; for (int i = startDiffRow.Value; i < rows.Count; i++) { args.Rows.Add(i); } this.OnRowsChanged.Notify(args, null, null); }
public override void Refresh() { if (_suspendRefresh) { _refreshPending = true; return; } OnRowsChangedEventArgs args = new OnRowsChangedEventArgs(); args.Rows = new List <int>(); for (int i = 0; i < Books.Count; i++) { args.Rows.Add(i); } this.OnDataLoaded.Notify(null, null, this); this.OnRowsChanged.Notify(args, null, this); }
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(""); }); }
/// <summary> /// Data Binds the standard Slick.DataView /// </summary> /// <param name="columns"></param> /// <param name="dataView"></param> /// <returns></returns> public Grid DataBindDataViewGrid(DataView dataView, List <Column> columns, string gridId, string pagerId, bool editable, bool allowAddNewRow) { // Always add an empty column on the end for reszing purposes ArrayEx.Add(columns, new Column()); GridOptions gridOptions = new GridOptions(); gridOptions.EnableCellNavigation = true; gridOptions.AutoEdit = editable; gridOptions.Editable = editable; gridOptions.EnableAddRow = allowAddNewRow; // Set non-variable options gridOptions.RowHeight = 20; gridOptions.HeaderRowHeight = 25; gridOptions.EnableColumnReorder = false; CheckboxSelectColumn checkBoxSelector = null; if (AddCheckBoxSelectColumn) { CheckboxSelectColumnOptions checkboxOptions = new CheckboxSelectColumnOptions(); checkboxOptions.cssClass = "sparkle-checkbox-column"; // Add check box column checkBoxSelector = new CheckboxSelectColumn(checkboxOptions); Column checkBoxColumn = checkBoxSelector.GetColumnDefinition(); columns.Insert(0, checkBoxColumn); } Grid grid = new Grid("#" + gridId, dataView, columns, gridOptions); grid.RegisterPlugin(checkBoxSelector); dataView.OnRowsChanged.Subscribe(delegate(EventData e, object a) { // Only invalided the rows that have changed OnRowsChangedEventArgs args = (OnRowsChangedEventArgs)a; if (args != null && args.Rows != null) { grid.InvalidateRows(args.Rows); grid.Render(); } }); //AddValidation(grid, dataView); // Add resize event jQuery.Window.Resize(delegate(jQueryEvent e) { // Set each column to be non resizable while we do the resize GridDataViewBinder.FreezeColumns(grid, true); grid.ResizeCanvas(); // Restore the resizing GridDataViewBinder.FreezeColumns(grid, false); }); // Add Reset binding Action reset = delegate() { }; Script.Literal("{0}.reset={1}", dataView, reset); // Add Refresh button AddRefreshButton(gridId, (DataViewBase)(object)dataView); // Add Selection Model RowSelectionModelOptions selectionModelOptions = new RowSelectionModelOptions(); selectionModelOptions.SelectActiveRow = true; RowSelectionModel selectionModel = new RowSelectionModel(selectionModelOptions); grid.SetSelectionModel(selectionModel); // Set sorting Action <EventData, object> onSort = delegate(EventData e, object a) { SortColData args = (SortColData)a; //SortDir = args.SortAsc ? 1 : -1; _sortColumnName = args.SortCol.Field; dataView.Sort(Comparer, args.SortAsc); }; grid.OnSort.Subscribe(onSort); return(grid); }
public override void Refresh() { //if (_suspendRefresh) // return; _suspendRefresh = true; // check if we have loaded this page yet int firstRowIndex = (int)paging.PageNum * (int)paging.PageSize; // If we have deleted all rows, we don't want to refresh the grid on the first page bool allDataDeleted = (paging.TotalRows == 0) && (DeleteData != null) && (DeleteData.Count > 0); List <int> rows = new List <int>(); if (firstRowIndex >= _pageLoaded) { this.OnDataLoading.Notify(null, null, null); string orderBy = ApplySorting(); // We need to load the data from the server int?fetchPageSize; fetchPageSize = this.paging.PageSize; if (String.IsNullOrEmpty(_fetchXml)) { return; } string parameterisedFetchXml = String.Format(_fetchXml, fetchPageSize, XmlHelper.Encode(this.paging.extraInfo), this.paging.PageNum + 1, orderBy); OrganizationServiceProxy.BeginRetrieveMultiple(parameterisedFetchXml, delegate(object result) { try { EntityCollection results = OrganizationServiceProxy.EndRetrieveMultiple(result, _entityType); // Set data int i = firstRowIndex; if (_lazyLoadPages) { // We are returning just one page - so add it into the data foreach (Entity e in results.Entities) { _data[i] = (Entity)e; ArrayEx.Add(rows, i); i = i + 1; } } else { // We are returning all results in one go _data = results.Entities.Items(); } // Notify DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs(); args.From = firstRowIndex; args.To = firstRowIndex + (int)paging.PageSize - 1; this.paging.TotalRows = results.TotalRecordCount; this.paging.extraInfo = results.PagingCookie; this.paging.FromRecord = firstRowIndex + 1; this.paging.TotalPages = Math.Ceil(results.TotalRecordCount / this.paging.PageSize); this.paging.ToRecord = Math.Min(results.TotalRecordCount, firstRowIndex + paging.PageSize); if (this._itemAdded) { this.paging.TotalRows++; this.paging.ToRecord++; this._itemAdded = false; } this.OnPagingInfoChanged.Notify(GetPagingInfo(), null, null); this.OnDataLoaded.Notify(args, null, null); } catch (Exception ex) { this.ErrorMessage = ex.Message; DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs(); args.ErrorMessage = ex.Message; this.OnDataLoaded.Notify(args, null, null); } }); } else { // We already have the data DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs(); args.From = 0; args.To = (int)paging.PageSize - 1; this.paging.FromRecord = firstRowIndex + 1; this.paging.ToRecord = Math.Min(this.paging.TotalRows, firstRowIndex + paging.PageSize); this.OnPagingInfoChanged.Notify(GetPagingInfo(), null, null); this.OnDataLoaded.Notify(args, null, null); this._itemAdded = false; } OnRowsChangedEventArgs refreshArgs = new OnRowsChangedEventArgs(); refreshArgs.Rows = rows; this.OnRowsChanged.Notify(refreshArgs, null, this); _suspendRefresh = false; }