DevExpress MVC PivotGrid自定义操作保持点火

时间:2015-10-07 00:23:39

标签: asp.net-mvc asp.net-mvc-5 devexpress devexpress-mvc

我正在使用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看起来没有响应。 这就是为什么我现在有一个名为已加载的布尔变量来检查它是否已经加载。这样做..但它是一个丑陋的黑客......因为每当用户在枢轴网格上做任何事情时,它就会不必要地去服务器。

当然必须有办法阻止这些行动一直开火?

0 个答案:

没有答案