我在网格设置中有这个:
var gridLayoutRepository = new GridLayoutRepository();
settings.ClientLayout = (s, e) =>
{
Debug.Write(e.LayoutData);
if (e.LayoutMode == ClientLayoutMode.Loading)
{
e.LayoutData = gridLayoutRepository.Load();
}
else
{
gridLayoutRepository.Save(e.LayoutData);
}
};
我想有一个用于在数据库中保存gridstate的按钮和一个用于重置它的按钮。你能救我吗?
答案 0 :(得分:1)
这是可能的。在网格设置中必须保存网格状态:
settings.ClientLayout = (s, e) =>
{
if (e.LayoutMode == ClientLayoutMode.Loading)
{
if (Session["myGridState"] != null)
e.LayoutData = (string)Session["myGridState"];
}
else
Session["myGridState"] = e.LayoutData;
};
然后点击按钮,你应该像这样保存网格状态:
<script type="text/javascript">
function SaveLayoutData() {
$.getJSON("@Url.Action("SaveLayoutData", "MyController" })", null,
function (result) {
if(result == 'success') {
alert("Layout save success");
}
});
}
</script>
在控制器中:
public JsonResult SaveLayoutData()
{
_gridStateRepository.Save(Session["myGridState"]);
return Json("success", JsonRequestBehavior.AllowGet);
}
当您加载网格时,您应该从数据库加载网格状态并将其写入Session [“myGridState”]