예제 #1
0
        public static void MakeOrderable(SlickGrid grid, Action <int[], int> handleMove)
        {
            var moveRowsPlugin = new SlickRowMoveManager(new SlickRowMoveManagerOptions
            {
                CancelEditOnDrag = true
            });

            moveRowsPlugin.OnBeforeMoveRows.Subscribe((e, data) =>
            {
                for (var i = 0; i < data.rows.length; i++)
                {
                    if (data.rows[i] == data.insertBefore || data.rows[i] == data.insertBefore - 1)
                    {
                        e.StopPropagation();
                        return(false);
                    }
                }
                return(true);
            });

            moveRowsPlugin.OnMoveRows.Subscribe((e, data) =>
            {
                int[] rows       = data.rows;
                int insertBefore = data.insertBefore;
                handleMove(rows, insertBefore);
                try { grid.SetSelectedRows(new int[0]); }
                catch { }
            });

            grid.RegisterPlugin(moveRowsPlugin);
        }
예제 #2
0
        protected virtual SlickGrid CreateSlickGrid()
        {
            List <SlickColumn> slickColumns;

            if (this.IsAsyncWidget())
            {
                slickColumns = new List <SlickColumn>();
            }
            else
            {
                slickColumns = PostProcessColumns(GetColumns());
            }

            var slickOptions = GetSlickOptions();
            var grid         = new SlickGrid(slickContainer, data: view.As <List <dynamic> >(), columns: slickColumns, options: slickOptions);

            grid.RegisterPlugin(new SlickAutoTooltips(new SlickAutoTooltipsOptions
            {
                EnableForHeaderCells = true
            }));

            this.slickGrid = grid;
            this.Rows      = this.slickGrid.As <GridRows <TItem> >();

            if (!IsAsyncWidget())
            {
                SetInitialSortOrder();
            }

            return(grid);
        }
예제 #3
0
        public DataGrid(jQueryObject container, TOptions opt = null)
            : base(container, opt)
        {
            var self = this;

            this.element.AddClass("s-DataGrid").Html("");
            this.element.AddClass("s-" + this.GetType().Name);
            this.element.AddClass("require-layout").Bind("layout", delegate
            {
                self.Layout();
            });

            Title = GetInitialTitle();

            var buttons = GetButtons();

            if (buttons != null)
            {
                CreateToolbar(buttons);
            }

            this.slickContainer = CreateSlickContainer();

            this.view = CreateView();

            this.slickGrid = CreateSlickGrid();

            if (UsePager())
            {
                CreatePager();
            }

            BindToSlickEvents();
            BindToViewEvents();

            if (buttons != null)
            {
                CreateToolbarExtensions();
            }

            UpdateDisabledState();

            if (PopulateWhenVisible())
            {
                LazyLoadHelper.ExecuteEverytimeWhenShown(element, () => self.RefreshIfNeeded(), false);
                if (element.Is(":visible"))
                {
                    view.Populate();
                }
            }
            else
            {
                view.Populate();
            }
        }
예제 #4
0
        public DataGrid(jQueryObject container, TOptions opt = null)
            : base(container, opt)
        {
            var self = this;

            this.element.AddClass("s-DataGrid").Html("");
            this.element.AddClass("s-" + this.GetType().Name);
            this.element.AddClass("require-layout").Bind("layout", delegate
            {
                self.Layout();
            });

            Title = GetInitialTitle();

            var buttons = GetButtons();

            if (buttons != null)
            {
                CreateToolbar(buttons);
            }

            this.slickContainer = CreateSlickContainer();

            this.view = CreateView();

            this.slickGrid = CreateSlickGrid();

            if (EnableFiltering())
            {
                CreateFilterBar();
            }

            if (UsePager())
            {
                CreatePager();
            }

            BindToSlickEvents();
            BindToViewEvents();

            if (buttons != null)
            {
                CreateToolbarExtensions();
            }

            UpdateDisabledState();

            if (!IsAsyncWidget())
            {
                InitialPopulate();
            }
        }
예제 #5
0
        public override void Destroy()
        {
            this.submitHandlers = null;

            if (this.toolbar != null)
            {
                this.toolbar.Destroy();
                this.toolbar = null;
            }

            if (this.slickGrid != null)
            {
                if (this.slickGridOnSort != null)
                {
                    this.slickGrid.OnSort.Unsubscribe(this.slickGridOnSort);
                    this.slickGridOnSort = null;
                }

                if (this.slickGridOnClick != null)
                {
                    this.slickGrid.OnSort.Unsubscribe(this.slickGridOnClick);
                    this.slickGridOnClick = null;
                }

                this.slickGrid.Destroy();
                this.slickGrid = null;
            }

            if (this.view != null)
            {
                this.view.OnRowsChanged.Clear();
                this.view.OnRowCountChanged.Clear();
                this.view.OnSubmit = null;
                this.view.SetFilter(null);
                dynamic viewRows = this.view.Rows;
                if (viewRows != null)
                {
                    viewRows.getItemMetadata = null;
                }
                this.view = null;
            }

            this.titleDiv = null;

            base.Destroy();
        }
예제 #6
0
        public override void Destroy()
        {
            this.submitHandlers = null;

            if (this.toolbar != null)
            {
                this.toolbar.Destroy();
                this.toolbar = null;
            }

            if (this.slickGrid != null)
            {
                if (this.slickGridOnSort != null)
                {
                    this.slickGrid.OnSort.Unsubscribe(this.slickGridOnSort);
                    this.slickGridOnSort = null;
                }

                if (this.slickGridOnClick != null)
                {
                    this.slickGrid.OnSort.Unsubscribe(this.slickGridOnClick);
                    this.slickGridOnClick = null;
                }

                this.slickGrid.Destroy();
                this.slickGrid = null;
            }

            if (this.view != null)
            {
                this.view.OnDataChanged.Clear();
                this.view.OnSubmit = null;
                this.view.SetFilter(null);
                this.view = null;
            }

            this.titleDiv = null;

            base.Destroy();
        }
예제 #7
0
        protected virtual SlickGrid CreateSlickGrid()
        {
            List <SlickColumn> slickColumns;

            if (this.IsAsyncWidget())
            {
                slickColumns = new List <SlickColumn>();
            }
            else
            {
                slickColumns = PostProcessColumns(GetColumns());
            }

            var     slickOptions = GetSlickOptions();
            var     self         = this;
            dynamic viewRows     = view.Rows;

            viewRows.getItemMetadata = new Func <int, dynamic>(delegate(int index)
            {
                var item = self.view.Rows[index];
                return(self.GetItemMetadata(item, index));
            });

            var grid = new SlickGrid(slickContainer, data: viewRows, columns: slickColumns, options: slickOptions);

            grid.RegisterPlugin(new SlickAutoTooltips(new SlickAutoTooltipsOptions
            {
                EnableForHeaderCells = true
            }));

            this.slickGrid = grid;

            if (!IsAsyncWidget())
            {
                SetInitialSortOrder();
            }

            return(grid);
        }
예제 #8
0
        protected virtual SlickGrid CreateSlickGrid()
        {
            var     slickColumns = PostProcessColumns(GetColumns());
            var     slickOptions = GetSlickOptions();
            var     self         = this;
            dynamic viewRows     = view.Rows;

            viewRows.getItemMetadata = new Func <int, dynamic>(delegate(int index)
            {
                var item = self.view.Rows[index];

                return(self.GetItemMetadata(item, index));
            });

            var grid = new SlickGrid(slickContainer, data: viewRows, columns: slickColumns, options: slickOptions);

            grid.RegisterPlugin(new SlickAutoTooltips(new SlickAutoTooltipsOptions
            {
                EnableForHeaderCells = true
            }));

            grid.SetSortColumns(GetDefaultSortBy().Map <SlickColumnSort>(s =>
            {
                var x = new SlickColumnSort();
                if (s != null && s.ToLower().EndsWith(" DESC"))
                {
                    x.ColumnId = s.Substr(0, s.Length - 5);
                    x.SortAsc  = false;
                }
                else
                {
                    x.ColumnId = s;
                    x.SortAsc  = true;
                }
                return(x);
            }));

            return(grid);
        }