C# 如何保存Kendo MVC网格的列顺序
我有一些15个字段的网格,我想用剑道列规范轻松地显示和隐藏这些字段,但我想保存屏幕,就像我将用2个scrrenshot解释的那样 在这张图片中,我想隐藏“UserPicture”列,我点击了它,我可以隐藏它 在这个屏幕上,当我点击第一个按钮时,我想保存这个网格列顺序 这是我的网格代码C# 如何保存Kendo MVC网格的列顺序,c#,jquery,asp.net-mvc,kendo-ui,kendo-grid,C#,Jquery,Asp.net Mvc,Kendo Ui,Kendo Grid,我有一些15个字段的网格,我想用剑道列规范轻松地显示和隐藏这些字段,但我想保存屏幕,就像我将用2个scrrenshot解释的那样 在这张图片中,我想隐藏“UserPicture”列,我点击了它,我可以隐藏它 在这个屏幕上,当我点击第一个按钮时,我想保存这个网格列顺序 这是我的网格代码 @( Html.Kendo().Grid<Models.webuser>() .Name("grdUserCreation") .DataSource(d =&g
@( Html.Kendo().Grid<Models.webuser>()
.Name("grdUserCreation")
.DataSource(d => d.Ajax().Read("GridUserCreationBinding", "UserCreation").Model(keys => keys.Id(k => k.Web_UserId)))
.HtmlAttributes("width: 100%;cellpadding:0;")
.Columns(columns => columns.LoadSettings(columnSettings))
.Events(events => events.Change("ongrdRowSelected").DataBound("onDataBoundusercre"))
.Selectable()
.Scrollable(scrolling => scrolling.Height(500))
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.Contains("Contains")
))
)
.Groupable(grouping => grouping.Enabled(true))
.Resizable(config =>
{
config.Columns(true);
})
.Reorderable(config =>
{
config.Columns(true);
})
.ColumnMenu()
)
@(Html.Kendo().Grid())
.名称(“grdUserCreation”)
.DataSource(d=>d.Ajax().Read(“GridUserCreationBinding”,“UserCreation”).Model(keys=>keys.Id(k=>k.Web\u UserId)))
.HtmlAttributes(“宽度:100%;单元格填充:0;”)
.Columns(Columns=>Columns.LoadSettings(columnSettings))
.Events(Events=>Events.Change(“ongrdRowSelected”).DataBound(“onDataBoundusercre”))
.可选()
.可滚动(滚动=>滚动高度(500))
.Sortable()
.Pageable(Pageable=>Pageable
.刷新(真)
.页面大小(真)
.按钮计数(5))
.Filterable(Filterable=>Filterable
.额外(错误)
.Operators(Operators=>Operators
.ForString(str=>str.Clear()
.StartsWith(“以开头”)
.Contains(“Contains”)
))
)
.Groupable(grouping=>grouping.Enabled(true))
.可调整大小(配置=>
{
config.Columns(true);
})
.Reorderable(配置=>
{
config.Columns(true);
})
.column菜单()
)
这是我的控制器部分,我在这里设置列设置
var columnSettings = new List<Kendo.Mvc.UI.GridColumnSettings>();
columnSettings = new List<Kendo.Mvc.UI.GridColumnSettings>()
{
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Web_UserId",
ClientTemplate="<input type='checkbox' value='#= Web_UserId #' />",
Width="70px",
IncludeInMenu=false,
Filterable=false
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Fleet_Id",
Width="auto",
Hidden=true,
IncludeInMenu=false
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="CariKod",
Width="150px",
Visible=false
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="UserPicture",
ClientTemplate="#=Picture(UserPicture)#",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Username",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Name",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Surname",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "FleetDesc",
Width="150px",
Visible= true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "MailAddress",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Mobilephone1",
Width="150px",
Hidden = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Mobilephone2",
Width="150px",
Hidden = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Phone",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Role_Id",
Hidden=true,
IncludeInMenu=false,
Width="150px"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Status_ID",
Width="150px",
Hidden = false
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "AlertSms",
Width="150px",
Hidden = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "AlertMail",
Width="150px",
Hidden = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Loc_ID",
Hidden=true,
IncludeInMenu=false,
Width="150px"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Dep_ID",
Hidden=true,
IncludeInMenu=false,
Width="150px"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member = "Carplate_Id",
Hidden=true,
IncludeInMenu=false,
Width="150px"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="RoleDesc",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="InvitationDate",
Width="150px",
Visible = true,
ClientTemplate = "#= kendo.toString(InvitationDate, 'dd.MM.yyyy hh:mm:ss tt') #"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="ActivationDate",
Width="150px",
Visible = true,
ClientTemplate = "#= kendo.toString(ActivationDate, 'dd.MM.yyyy hh:mm:ss tt') #"
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="LocName",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="DepName",
Width="150px",
Visible = true
},
new Kendo.Mvc.UI.GridColumnSettings
{
Member="VehName",
Width="150px",
Visible = true
}
};
var columnSettings=new List();
columnSettings=新列表()
{
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Web\u UserId”,
ClientTemplate=“”,
Width=“70px”,
IncludeInMenu=false,
可过滤=错误
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Fleet\u Id”,
Width=“自动”,
隐藏=正确,
IncludeInMenu=false
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“CariKod”,
Width=“150px”,
可见=假
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“UserPicture”,
ClientTemplate=“#=图片(用户图片)#”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Username”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Name”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“姓氏”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“FleetDesc”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“maildaddress”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Mobilephone1”,
Width=“150px”,
隐藏=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Mobilephone2”,
Width=“150px”,
隐藏=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Phone”,
Width=“150px”,
可见=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Role\u Id”,
隐藏=正确,
IncludeInMenu=false,
宽度=“150px”
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“Status\u ID”,
Width=“150px”,
隐藏=错误
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“AlertSms”,
Width=“150px”,
隐藏=真
},
新建Kendo.Mvc.UI.GridColumnSettings
{
Member=“AlertMail”,
Width=“150px”,
隐藏=真
var localStorageKey = "UserAdministrationUserGridOptions";
function onDataBound(arg)
{
var grid = $("#UserAdministrationUserGrid").data("kendoGrid");
localStorage[localStorageKey] = kendo.stringify(grid.getOptions());
}
$(function () {
// pull client grid state and apply to grid (filters, current page, sorts, etc).
});
function setGridOptions() {
var options = localStorage[localStorageKey];
if (options) {
$("#UserAdministrationUserGrid").data("kendoGrid").setOptions(JSON.parse(options));
}
}