コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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);
        }