GridViewUserSettingsEditor

in namespace DotVVM.BusinessPack.Controls

Renders a control allowing users to edit GridView settings (show / hide columns, etc.).

Usage & Scenarios

GridViewUserSettingsEditor displays a checkbox for each column in a Business Pack GridView. Users can show or hide columns without changing the grid's data.

Sample 1: Choose visible columns

Bind the grid and the editor to the same UserSettings property. This sample starts with the bin hidden. Check Storage bin to reveal it, or drag the grid headers to reorder columns (AllowReorderColumns is a grid option).

Use stable, unique ColumnName values so saved settings still identify columns after their headers or positions change. You can also leave the bound property null initially: the grid then populates settings from its columns. To remember preferences across visits, save and restore the GridViewUserSettings object in your application.

<bp:GridView DataSource="{value: Stock}" UserSettings="{value: Settings}"
             AllowReorderColumns="true">
    <Columns>
        <bp:GridViewTextColumn ColumnName="Item" HeaderText="Item" Value="{value: Item}" />
        <bp:GridViewTextColumn ColumnName="Bin" HeaderText="Storage bin" Value="{value: Bin}" />
    </Columns>
</bp:GridView>

<h4>Visible columns</h4>
<bp:GridViewUserSettingsEditor UserSettings="{value: Settings}" />
using System.Linq;
using DotVVM.BusinessPack.Controls;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.GridViewUserSettingsEditor.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public BusinessPackDataSet<StockItem> Stock { get; set; } = new BusinessPackDataSet<StockItem>();
        public GridViewUserSettings Settings { get; set; } = new GridViewUserSettings {
            ColumnsSettings = {
                new GridViewColumnSettings { ColumnName = "Item", DisplayText = "Item", DisplayOrder = 0 },
                new GridViewColumnSettings { ColumnName = "Bin", DisplayText = "Storage bin", DisplayOrder = 1, Visible = false }
            }
        };

        public ViewModel()
        {
            Stock.LoadFromQueryable(new[] {
                new StockItem { Item = "Notebook", Bin = "A1" },
                new StockItem { Item = "Pencil", Bin = "B2" }
            }.AsQueryable());
        }
    }

    public class StockItem
    {
        public string Item { get; set; }
        public string Bin { get; set; }
    }
}

Properties

Name Type Description Notes Default Value
property icon UserSettings GridViewUserSettings Gets or sets the GridViewUserSettings instance to edit.
attribute
inner element
static value
bindable
default
null

HTML produced by the control