jQuery Dashboard 插件 - 如何保存状态更改

发布于 2024-10-19 18:37:13 字数 589 浏览 2 评论 0原文

我已经开始使用此处演示的仪表板插件 - http://www.gxdeveloperweb。 com/dashboardplugin/demo/dashboard.html

我正在努力处理文档。主要是关于如何保存最终用户更改的仪表板配置。

在文档中,它告诉您如何执行“dashboardStateChange”:

dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetAdded","widget":widget});

但我真的不明白它在仪表板设置中的位置,以及如何使用它来保存更改。我认为当发生某些事情时我可以从 DOM 中访问仪表板状态更改,但甚至无法理解这是如何完成的。

有没有人有任何关于在仪表板状态发生变化时保存仪表板的提示?我希望它能够与保存仪表板设置的 php 脚本对话。

不幸的是,没有任何关于此类功能的优秀教程。

谢谢!

I've started using the dashboard plugin which is demoed here - http://www.gxdeveloperweb.com/dashboardplugin/demo/dashboard.html

I'm struggling with the documentation. Primarily on how to save dashboard configurations altered by the enduser.

In the documentation, it tells you how to do a "dashboardStateChange":

dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetAdded","widget":widget});

But I don't really understand where this is to go within the dashboard setup, and how you use this to save the changes. I thought I could could access dashboardStateChange from within the DOM when something happens, but even failing to understand how this is done.

Has anyone got any tips on saving the dashboard whenever its state has changed? I would like it to talk to a php script which saves the dashboard setup.

Unfortunately there aren't any great tutorials on this sort of functionality.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿咻 2024-10-26 18:37:13

我不知道这个问题是否仍然有趣,但我已经使用这个插件很长一段时间了,它实际上很容易使用。
几乎所有答案都可以在插件附带的示例中找到,对于您的问题,您可能需要查看以下示例代码,我用它来使仪表板的当前布局在服务器上持久化。

请注意,“saveID”是“保存”按钮的 ID,“saveConfiguration”是在服务器上保存布局的 URL。

// binding for saving the current configuration
$("#saveID").bind("click", function () {
    var conf = $.parseJSON(dashboard.serialize()),
        // get the serialized configuration
        len = conf.data.length,
        // generate the new parameter to submit
        para = "lay=" + conf.layout + "&len=" + len,
        i = 0;
    for (i = 0; i < len; i += 1) {
        para = para + "&pid" + i + "=" + conf.data[i].id + "&col" + i + "=" + conf.data[i].column;
    }

    // Invoke the "saveConfiguration" on the server via AJAX
    $.ajax({
        url: "saveConfiguration",
        data: para,
        dataType: "json",
        success: function (jsonResponse) {
            if (jsonResponse.valid === true) {
                alert("Configuration has been saved");
            } else {
                alert("Error when trying to save the configuration\n" + jsonResponse.error);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(textStatus + " - " + errorThrown);
        }
    });
    return false;
});

I don't know if this question is still of interest but I've been using this plugin for quite a while and it's actually quite easy to use.
Pretty much all of the answer can be found in the example that comes with the plugin and to your problem you might want to have a look at the following example code that I use to make the current layout of the dashboard persistent on the server.

Please note that "saveID" is the ID of a Save button and "saveConfiguration" is the URL that save the layout on the server.

// binding for saving the current configuration
$("#saveID").bind("click", function () {
    var conf = $.parseJSON(dashboard.serialize()),
        // get the serialized configuration
        len = conf.data.length,
        // generate the new parameter to submit
        para = "lay=" + conf.layout + "&len=" + len,
        i = 0;
    for (i = 0; i < len; i += 1) {
        para = para + "&pid" + i + "=" + conf.data[i].id + "&col" + i + "=" + conf.data[i].column;
    }

    // Invoke the "saveConfiguration" on the server via AJAX
    $.ajax({
        url: "saveConfiguration",
        data: para,
        dataType: "json",
        success: function (jsonResponse) {
            if (jsonResponse.valid === true) {
                alert("Configuration has been saved");
            } else {
                alert("Error when trying to save the configuration\n" + jsonResponse.error);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(textStatus + " - " + errorThrown);
        }
    });
    return false;
});
沉鱼一梦 2024-10-26 18:37:13

您可以使用内置的仪表板功能来快速保存简单的。在初始化仪表板的页面上,将其放在 initDashboard() 函数之后,但在 dashboard.init() 之前:

$("#savebutton_id").bind("click", function () {
    dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetMoved","widget":"w"});
    alert("Saved");
});

然后放置一个带有以下内容的 Button 或 Link HTML 代码中某处的 id savebutton_id 。当您单击它时,仪表板会将序列化配置发送到您预定义的 stateChangeUrl

You can use the built in dashboard function to save quick & easy. On the page where you init the dashboard, put this after the initDashboard() function, but before the dashboard.init():

$("#savebutton_id").bind("click", function () {
    dashboard.element.trigger("dashboardStateChange",{"stateChange":"widgetMoved","widget":"w"});
    alert("Saved");
});

Then you put a Button or Link with the id savebutton_id somewhere in your HTML-Code. When you click it, the dashboard will send the serialized configuration to your predefined stateChangeUrl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文