public static void init() { MultiSearchViewModel2013 vm = new MultiSearchViewModel2013(); // Create Grids FetchQuerySettings[] searches = vm.Config.GetItems(); jQueryObject searchResultsDiv = jQuery.Select("#searchResults"); jQuery.Window.Resize(delegate(jQueryEvent e) { OnResizeSearchResults(searchResultsDiv); }); OnResizeSearchResults(searchResultsDiv); jQuery.Select(".sparkle-xrm").Bind("onmousewheel mousewheel DOMMouseScroll", OnSearchResultsMouseScroll); int i = 0; foreach (FetchQuerySettings config in searches) { List<Column> cardColumn = new List<Column>(new Column(ColumnProperties.Id, "card-column", ColumnProperties.Options,config.Columns, ColumnProperties.Name, "Name", ColumnProperties.Width, 290, ColumnProperties.CssClass, "card-column-cell")); cardColumn[0].Formatter = RenderCardColumnCell; cardColumn[0].DataType = "PrimaryNameLookup"; config.Columns[0].DataType = "PrimaryNameLookup"; // This is so that clicking on the column opens the record GridDataViewBinder dataViewBinder = new GridDataViewBinder(); GridOptions gridOptions = new GridOptions(); gridOptions.EnableCellNavigation = true; gridOptions.AutoEdit = false; gridOptions.Editable = false; gridOptions.EnableAddRow = false; // Set height to the number of columns int columns = config.Columns.Count; gridOptions.RowHeight = (columns>3? 3 : columns) * 16; ; if (gridOptions.RowHeight < 70) gridOptions.RowHeight = 70; gridOptions.HeaderRowHeight = 0; string gridId = "grid" + i.ToString() + "container"; DataViewBase dataView = config.DataView; Grid grid = new Grid("#" + gridId, dataView, cardColumn, gridOptions); grids[i] = grid; AddResizeEventHandlers(grid, gridId); dataViewBinder.DataBindEvents(grid, dataView, gridId); dataViewBinder.BindClickHandler(grid); i++; } // Data Bind ViewBase.RegisterViewModel(vm); }
public static void init() { DataGroupingViewModel vm = new DataGroupingViewModel(); NumberFormatInfo numberFormatInfo = NumberEx.GetNumberFormatInfo(); numberFormatInfo.MinValue = 0; numberFormatInfo.MaxValue = 1000; numberFormatInfo.Precision = 2; BooleanBindingOptions boolFormatInfo = new BooleanBindingOptions(); boolFormatInfo.FalseOptionDisplayName = "No"; boolFormatInfo.TrueOptionDisplayName = "Yes"; // Add Columns SubTotalsFormatterDelegate sumTotalsFormatterDelegate = SumTotalsFormatter; SubTotalsFormatterDelegate avgTotalsFormatterDelegate = AvgTotalsFormatter; FormatterDelegate percentageFormatter = XrmNumberEditor.Formatter; FormatterDelegate checkboxFormatter = XrmBooleanEditor.Formatter; List<Column> columns = new List<Column>( new Column( ColumnProperties.Id, "sel", ColumnProperties.Name, "#", ColumnProperties.Field, "num", ColumnProperties.CssClass, "cell-selection", ColumnProperties.Width, 40, ColumnProperties.Resizable, false, ColumnProperties.Selectable, false, ColumnProperties.Focusable, false), new Column( ColumnProperties.Id, "title", ColumnProperties.Name, "Title", ColumnProperties.Field, "title", ColumnProperties.Width, 70, ColumnProperties.MinWidth, 50, ColumnProperties.CssClass, "cell-title", ColumnProperties.Sortable, true, ColumnProperties.Editor, XrmTextEditor.TextEditor), new Column( ColumnProperties.Id, "duration", ColumnProperties.Name, "Duration", ColumnProperties.Field, "duration", ColumnProperties.Width, 70, ColumnProperties.Sortable, true, ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate), new Column( ColumnProperties.Id, "%", ColumnProperties.Name, "% Complete", ColumnProperties.Field, "percentComplete", ColumnProperties.Width, 80, ColumnProperties.Formatter, percentageFormatter, ColumnProperties.Options, numberFormatInfo, ColumnProperties.Sortable, true, ColumnProperties.GroupTotalsFormatter, avgTotalsFormatterDelegate), new Column( ColumnProperties.Id, "start", ColumnProperties.Name, "Start", ColumnProperties.Field, "start", ColumnProperties.MinWidth, 60, ColumnProperties.Sortable, true), new Column( ColumnProperties.Id, "finish", ColumnProperties.Name, "Finish", ColumnProperties.Field, "finish", ColumnProperties.MinWidth, 60, ColumnProperties.Sortable, true), new Column( ColumnProperties.Id, "cost", ColumnProperties.Name, "Cost", ColumnProperties.Field, "cost", ColumnProperties.Width, 90, ColumnProperties.Sortable, true, ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate), new Column( ColumnProperties.Id, "effort-driven", ColumnProperties.Name, "Effort Driven", ColumnProperties.Width, 80, ColumnProperties.MinWidth, 20, ColumnProperties.CssClass, "cell-effort-driven", ColumnProperties.Field, "effortDriven", ColumnProperties.Formatter, checkboxFormatter, ColumnProperties.Options, boolFormatInfo, ColumnProperties.Sortable, true) ); GridOptions options = new GridOptions(); options.EnableCellNavigation = true; options.Editable = true; DataViewBase view = (DataViewBase)(object)vm.Projects; GridDataViewBinder binder = new GridDataViewBinder(); Grid grid = binder.DataBindDataViewGrid(vm.Projects, columns, "myGrid", null, true, false); // register the group item metadata provider to add expand/collapse group handlers grid.RegisterPlugin(new GroupItemMetadataProvider()); // Data Bind ViewBase.RegisterViewModel(vm); }
public Grid(string containerId, object data, List <Column> columns, GridOptions options) { }
public Grid(string containerId, object data, List<Column> columns, GridOptions options) { }
/// <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; }
/// <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 static void SetUpGrids(TimeSheetViewModel vm) { GridOptions daysGridOpts = new GridOptions(); daysGridOpts.EnableCellNavigation = true; daysGridOpts.EnableColumnReorder = false; daysGridOpts.AutoEdit = false; daysGridOpts.Editable = true; daysGridOpts.RowHeight = 20; daysGridOpts.HeaderRowHeight = 25; daysGridOpts.ForceFitColumns = false; daysGridOpts.EnableAddRow = true; // Create Timesheet Grid DataViewBase daysDataView = vm.Days; List<Column> columns = new List<Column>(); GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity"); XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode"); GridDataViewBinder.AddColumn(columns, "Mon", 50, "day0"); GridDataViewBinder.AddColumn(columns, "Tue", 50, "day1"); GridDataViewBinder.AddColumn(columns, "Wed", 50, "day2"); GridDataViewBinder.AddColumn(columns, "Thu", 50, "day3"); GridDataViewBinder.AddColumn(columns, "Fri", 50, "day4"); GridDataViewBinder.AddColumn(columns, "Sat", 50, "day5"); GridDataViewBinder.AddColumn(columns, "Sun", 50, "day6"); daysGrid = new Grid("#timesheetGridContainer", daysDataView, columns, daysGridOpts); GridDataViewBinder daysDataBinder = new GridDataViewBinder(); daysDataBinder.DataBindEvents(daysGrid, daysDataView, "timesheetGridContainer"); // Set the totals row meta data daysDataView.OnGetItemMetaData += delegate(object item) { DayEntry day = (DayEntry)item; if (day != null && day.isTotalRow) { ItemMetaData metaData = new ItemMetaData(); metaData.Editor = null; metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext) { if (columnDef.Field == "activity") return "Total"; else return Formatters.DefaultFormatter(row, cell, value, columnDef, dataContext); }; metaData.CssClasses = "days_total_row"; return metaData; } else return null; }; daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView); // --------------------------------------- // Sessions Grid // --------------------------------------- DataViewBase sessionsDataView = vm.SessionDataView; List<Column> sessionGridCols = new List<Column>(); GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols); XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 200, "dev1_description")); XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 200, "dev1_starttime"), true); XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newStartTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_EndTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime); result.Valid = isValid; result.Message = "The start time must be before the end time"; } else result.Valid = true; return result; }; XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newEndTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_StartTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime); result.Valid = isValid; result.Message = "The end time must be after the start time"; } else result.Valid = true; return result; }; XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 200, "dev1_duration")); GridDataViewBinder sessionsDataBinder = new GridDataViewBinder(); sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true); sessionsDataBinder.DataBindSelectionModel(sessionsGrid, sessionsDataView); daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args) { CellSelection activeCell = daysGrid.GetActiveCell(); if (activeCell != null) { if (activeCell.Cell < 2) { // Whole activity is selected vm.Days.SelectedDay = null; } else { vm.Days.SelectedDay = activeCell.Cell - 1; } } }); }