public void AddValidation(Grid grid, DataViewBase dataView) { Action <string, Column> setValidator = delegate(string attributeName, Column col) { col.Validator = delegate(object value, object item) { Func <string, GridValidatorDelegate> indexer = dataView.GridValidationIndexer(); GridValidatorDelegate validationRule = indexer(attributeName); if (validationRule != null) { return(validationRule(value, item)); } else { ValidationResult result = new ValidationResult(); result.Valid = true; return(result); } }; }; if (dataView.GridValidationIndexer() != null) { foreach (Column col in grid.GetColumns()) { string fieldName = col.Field; setValidator(fieldName, col); } } }
public Grid DataBindXrmGrid(DataViewBase 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.ForceFitColumns = true; 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); this.DataBindSelectionModel(grid, dataView); if (!string.IsNullOrEmpty(pagerId)) { CrmPagerControl pager = new CrmPagerControl(dataView, grid, jQuery.Select("#" + pagerId)); } DataBindEvents(grid, dataView, gridId); AddValidation(grid, dataView); AddRefreshButton(gridId, dataView); // Add resize event jQuery.Window.Resize(delegate(jQueryEvent e){ // Set each column to be non resizable while we do the resize FreezeColumns(grid, true); grid.ResizeCanvas(); // Restore the resizing FreezeColumns(grid, false); }); dataView.OnDataLoaded.Subscribe(delegate(EventData e, object o) { FreezeColumns(grid, false); }); return(grid); }
public CrmPagerControl(DataViewBase dataView, Grid grid, jQueryObject container) { _dataView = dataView; _grid = grid; _container = container; jQuery.OnDocumentReady(delegate() { init(); }); }
public CrmPagerControl(DataViewBase dataView, Grid grid, jQueryObject container) { _dataView = dataView; _grid = grid; _container = container; jQuery.OnDocumentReady(delegate() { init(); }); }
public void AddRefreshButton(string gridId, DataViewBase dataView) { jQueryObject gridDiv = jQuery.Select("#" + gridId); jQueryObject refreshButton = jQuery.FromHtml("<div id='refreshButton' class='sparkle-grid-refresh-button' style='left: auto; right: 0px; display: inline;'><a href='#' id='refreshButtonLink' tabindex='0'><span id='grid_refresh' class='sparkle-grid-refresh-button-img' style='cursor:pointer'></span></a></div>").AppendTo(gridDiv); refreshButton.Find("#refreshButtonLink").Click(delegate(jQueryEvent e) { dataView.Reset(); dataView.Refresh(); }); }
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 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 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); }
/// <summary> /// DataBinds a DataView that inherits from DataViewBase /// /// </summary> /// <param name="dataView"></param> /// <param name="columns"></param> /// <param name="gridId"></param> /// <param name="pagerId"></param> /// <param name="editable"></param> /// <param name="allowAddNewRow"></param> /// <returns></returns> public Grid DataBindXrmGrid(DataViewBase 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 = PageEx.MajorVersion==2013 ? 30 : 20; gridOptions.HeaderRowHeight = 25; //gridOptions.ForceFitColumns = true; 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); this.DataBindSelectionModel(grid, dataView); if (!string.IsNullOrEmpty(pagerId)) { CrmPagerControl pager = new CrmPagerControl(dataView, grid, jQuery.Select("#" + pagerId)); } DataBindEvents(grid, dataView, gridId); AddValidation(grid, dataView); AddRefreshButton(gridId, dataView); // Add resize event jQuery.Window.Resize(delegate(jQueryEvent e){ // Set each column to be non resizable while we do the resize FreezeColumns(grid, true); grid.ResizeCanvas(); // Restore the resizing FreezeColumns(grid, false); }); dataView.OnDataLoaded.Subscribe(delegate(EventData e, object o) { FreezeColumns(grid,false); }); _grid = grid; 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 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(""); }); }
public void AddValidation(Grid grid, DataViewBase dataView) { Action<string, Column> setValidator = delegate(string attributeName, Column col) { col.Validator = delegate(object value, object item) { Func<string,GridValidatorDelegate> indexer = dataView.GridValidationIndexer(); GridValidatorDelegate validationRule = indexer(attributeName); if (validationRule != null) return validationRule(value, item); else { ValidationResult result = new ValidationResult(); result.Valid = true; return result; } }; }; if (dataView.GridValidationIndexer() != null) { foreach (Column col in grid.GetColumns()) { string fieldName = col.Field; setValidator(fieldName, col); } } }
public void AddRefreshButton(string gridId, DataViewBase dataView) { jQueryObject gridDiv = jQuery.Select("#" + gridId); jQueryObject refreshButton = jQuery.FromHtml("<div id='refreshButton' class='sparkle-grid-refresh-button' style='left: auto; right: 0px; display: inline;'><a href='#' id='refreshButtonLink' tabindex='0'><img id='grid_refresh' src='../../sparkle_/css/images/transparent_spacer.gif' class='sparkle-grid-refresh-button-img' style='cursor:pointer' alt='Refresh list' title='Refresh list'></a></div>").AppendTo(gridDiv); refreshButton.Find("#refreshButtonLink").Click(delegate(jQueryEvent e) { dataView.Reset(); dataView.Refresh(); }); }
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); }