/// <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; CheckboxSelectColumnOptions checkboxOptions = new CheckboxSelectColumnOptions(); checkboxOptions.cssClass = "sparkle-checkbox-column"; // Add check box column CheckboxSelectColumn 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 void DataBindSelectionModel(Grid grid, DataViewBase dataView) { // Set up selection model if needed // Create selection model RowSelectionModelOptions selectionModelOptions = new RowSelectionModelOptions(); selectionModelOptions.SelectActiveRow = true; RowSelectionModel selectionModel = new RowSelectionModel(selectionModelOptions); // Bind two way sync of selected rows // NOTE: the row index on the grid is not the row index in the data view due to paging bool inHandler = false; selectionModel.OnSelectedRangesChanged.Subscribe(delegate(EventData e, object args) { if (inHandler) return; inHandler = true; dataView.RaiseOnSelectedRowsChanged((SelectedRange[])args); inHandler = false; }); dataView.OnSelectedRowsChanged+=delegate() { if (inHandler) return; inHandler = true; SelectedRange[] ranges = dataView.GetSelectedRows(); int[] selectedRows = new int[ranges.Length]; for (int i=0;i<selectedRows.Length;i++) { selectedRows[i] = ranges[i].FromRow.Value; } grid.SetSelectedRows(selectedRows); inHandler = false; }; grid.SetSelectionModel(selectionModel); }
public void DataBindSelectionModel(Grid grid, DataViewBase dataView) { // Set up selection model if needed // Create selection model RowSelectionModelOptions selectionModelOptions = new RowSelectionModelOptions(); selectionModelOptions.SelectActiveRow = SelectActiveRow; selectionModelOptions.MultiRowSelect = this.MultiSelect; RowSelectionModel selectionModel = new RowSelectionModel(selectionModelOptions); // Bind two way sync of selected rows // NOTE: the row index on the grid is not the row index in the data view due to paging bool inHandler = false; selectionModel.OnSelectedRangesChanged.Subscribe(delegate(EventData e, object args) { //if (grid.GetEditorLock().IsActive()) //{ // e.StopPropagation(); // return; //} if (inHandler) return; inHandler = true; // Has the selected row changeD? SelectedRange[] selectedRows = dataView.GetSelectedRows(); SelectedRange[] newSelectedRows = (SelectedRange[])args; bool changed = selectedRows.Length!=newSelectedRows.Length; if (!changed) { // Compare the actual selected rows for (int i = 0; i < selectedRows.Length; i++) { if (selectedRows[i].FromRow!=newSelectedRows[i].FromRow) { changed = true; break; } } } if (changed) { dataView.RaiseOnSelectedRowsChanged(newSelectedRows); } inHandler = false; }); dataView.OnSelectedRowsChanged+=delegate() { //if (grid.GetEditorLock().IsActive()) // return; if (inHandler) return; inHandler = true; SelectedRange[] ranges = dataView.GetSelectedRows(); int[] selectedRows = new int[ranges.Length]; for (int i=0;i<selectedRows.Length;i++) { selectedRows[i] = ranges[i].FromRow.Value; } grid.SetSelectedRows(selectedRows); inHandler = false; }; grid.SetSelectionModel(selectionModel); }