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 | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| UserSettings | GridViewUserSettings | Gets or sets the GridViewUserSettings instance to edit. |
attribute
bindable
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |