我正在使用 DevExpress MVC Pivot Grid 并尝试解决加载和保存布局的一些问题。到目前为止,我有以下内容:
我在PivotGridSettings中设置了我的CustomActionRouteValues ,如下所示:
CustomActionRouteValues = new { Controller = "Home", Action = "PivotGridCustomCallback" },
这指向以下几点:
public ActionResult PivotGridCustomCallback(string action, string reportName)
{
if (string.IsNullOrEmpty(reportName))
{
reportName = "Report 1";
}
var settings = PivotGridLayoutHelper.DefaultPivotGridSettings;
if (action == "Save")
{
// TODO: Find a better solution than this. At the moment, if Save is called once, it is then called again every time the user changes the layout.. which is why we have the 'saved' variable here.
bool saved = false;
settings.AfterPerformCallback = (sender, e) =>
{
if (saved)
{
return;
}
SaveLayout(((MVCxPivotGrid)sender).SaveLayoutToString(), reportName);
saved = true;
};
}
else if (action == "Load")
{
// TODO: Find a better solution than this. At the moment, if Load is called once, it is then called again every time the user changes the layout.. which is why we have the 'loaded' variable here.
bool loaded = false;
string layoutString = LoadLayout(reportName);
if (!string.IsNullOrEmpty(layoutString))
{
settings.BeforeGetCallbackResult = (sender, e) =>
{
if (loaded)
{
return;
}
((MVCxPivotGrid)sender).LoadLayoutFromString(layoutString, PivotGridWebOptionsLayout.DefaultLayout);
loaded = true;
};
}
}
ViewBag.PivotSettings = settings;
return PartialView("PivotPartial");
}
正如您在代码注释中看到的那样,问题是在执行一次操作后,每次我进行任何类型的更改时都会调用它。所以,例如......假设我加载了一份报告......这很好......但是当我尝试扩展某些东西或添加一个字段......或者做任何事情时,UI上似乎没有发生任何事情......我发现那是因为立即,再次调用此代码:
settings.BeforeGetCallbackResult = (sender, e) =>
{
((MVCxPivotGrid)sender).LoadLayoutFromString(layoutString, PivotGridWebOptionsLayout.DefaultLayout);
};
这只是将值重置为已保存的布局,这意味着 UI 在尝试更改任何内容时看起来似乎没有响应。这就是为什么我现在有一个名为加载的布尔变量来检查它是否已经加载。那行得通..但它是一个丑陋的黑客..因为每次用户在枢轴网格上做任何事情时,它都会对服务器进行不必要的访问。
肯定有办法防止这些动作一直触发吗?