Beispiel #1
0
        public static void Configure(this GridViewSettings gridSettings, GridData gridData, HtmlHelper html, ViewContext viewContext, GridSettingOptions gridSettingOptions = null, params string[] arguments)
        {
            gridSettings.Width  = Unit.Percentage(100);
            gridSettings.Height = Unit.Percentage(100);

            if (gridSettingOptions == null)
            {
                gridSettingOptions = new GridSettingOptions();
            }

            gridSettings.Settings.HorizontalScrollBarMode = gridSettingOptions.HorizontalScrollBarMode;
            gridSettings.Settings.VerticalScrollBarMode   = gridSettingOptions.VerticalScrollBarMode;

            if (gridSettingOptions.VerticalScrollableHeight.HasValue)
            {
                gridSettings.Settings.VerticalScrollableHeight = gridSettingOptions.VerticalScrollableHeight.Value;
            }

            //Grid Specific configurations
            gridSettings.KeyFieldName = gridData.Key;
            gridSettings.Name         = $"{gridData.Name}";


            gridSettings.Styles.Header.Wrap = DefaultBoolean.True;

            gridSettings.SettingsExport.EnableClientSideExportAPI = true;
            gridSettings.SettingsExport.ExcelExportMode           = DevExpress.Export.ExportType.DataAware;

            if (gridSettingOptions.ShowTitle)
            {
                gridSettings.Settings.ShowTitlePanel = true;
                gridSettings.SettingsText.Title      = gridData.Title;
            }
            else
            {
                gridSettings.Caption = gridData.Title;
            }

            if (gridData.GroupSetting != null)
            {
                gridSettings.SettingsBehavior.AutoExpandAllGroups = gridData.GroupSetting.AutoExpandAllGroups;
                gridSettings.SettingsBehavior.MergeGroupsMode     = gridData.GroupSetting.GroupMode;

                if (gridData.GroupSetting.GroupFormatForMergedGroup != null)
                {
                    gridSettings.Settings.GroupFormatForMergedGroup = gridData.GroupSetting.GroupFormatForMergedGroup;
                }

                if (gridData.GroupSetting.MergedGroupSeparator != null)
                {
                    gridSettings.Settings.MergedGroupSeparator = gridData.GroupSetting.MergedGroupSeparator;
                }
            }


            gridSettings.Styles.AlternatingRow.BackColor = gridData.AlternateRowColor;

            #region Configure Toolbars


            if (gridData.ToolBarOptions.Show)
            {
                gridSettings.AddToolBar(html, viewContext, gridData);
            }
            #endregion

            #region Configure Columns
            foreach (var col in gridData.DisplayColumns.OrderBy(c => c.Order))
            {
                if (col.ColumnAction != null)
                {
                    gridSettings.Columns.Add(col.ColumnAction);
                    var lcol = gridSettings.Columns[col.Name] as MVCxGridViewColumn;
                    lcol.Hide(!col.IsVisible);

                    continue;
                }

                MVCxGridViewColumn gcol = gridSettings.Columns.Add(col.Name, col.DisplayName, col.ColumnType);
                gcol.Set(col);
            }
            #endregion

            #region Configure Callback Route
            if (gridData.CallBackRoute != null)
            {
                gridSettings.CallbackRouteValues = gridData.CallBackRoute;
            }
            #endregion

            #region Configure Buttons
            foreach (var btn in gridData.Buttons)
            {
                gridSettings.AddButton(btn.Type, btn.Display);
            }
            #endregion



            if (gridData.ButtonOptions != null)
            {
                gridSettings.CommandColumn.Visible = gridData.ButtonOptions.Show;
                gridSettings.CommandColumn.ShowNewButtonInHeader = gridData.ButtonOptions.DisplayAddButtonInGridHeader;
                gridSettings.CommandColumn.ShowNewButton         = gridData.ButtonOptions.DisplayAddButton;
                gridSettings.CommandColumn.ShowCancelButton      = gridData.ButtonOptions.DisplayCancelButton;
                gridSettings.CommandColumn.ShowEditButton        = gridData.ButtonOptions.DisplayEditButton;
                gridSettings.CommandColumn.ShowUpdateButton      = gridData.ButtonOptions.DisplayUpdateButton;
                gridSettings.CommandColumn.ShowDeleteButton      = gridData.ButtonOptions.DisplayDeleteButton;
                gridSettings.CommandColumn.Width = Unit.Percentage(gridData.ButtonOptions.Width);
            }


            gridSettings.CommandColumn.Width   = 70;
            gridSettings.CommandColumn.Caption = " ";



            #region Configure Routes
            foreach (var route in gridData.Routes)
            {
                gridSettings.AddRoutes(route.Type, route.Route);
            }
            #endregion

            #region Configure Layout

            gridSettings.BuildEditLayout(gridData.FormLayout);
            #endregion

            gridSettings.SettingsBehavior.ConfirmDelete = true;

            gridSettings.SettingPaging(gridData);

            if (gridData.RowInitializeEvent != null)
            {
                gridSettings.InitNewRow = gridData.RowInitializeEvent;
            }

            if (gridData.RowEditEvent != null)
            {
                gridSettings.CellEditorInitialize = gridData.RowEditEvent;
            }

            //settings.SetupGlobalGridViewBehavior();
        }