如何在更改页面或在Kendo Grid中排序时提示用户已进行编辑 [英] How to prompt user that edits have been made upon changing pages or sorting in Kendo Grid

查看:98
本文介绍了如何在更改页面或在Kendo Grid中排序时提示用户已进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了网格.在我的应用程序中,我正在使用处于批量编辑模式,以允许数据输入人员快速编辑屏幕上的多个记录.设置此特定网格以允许分页和排序.

I have run into an issue with the kendo-ui grid that I can't solve. In my application I am using kendo-grid in batch edit mode to allow a data entry person to quickly make edits to several records on a screen. This particular grid is set to allow paging and sorting.

我正在寻找一种方法来提示用户尝试排序或单击其中一个页面链接,同时在特定页面上进行了编辑(如在datagrid/datasource的页面中).如果用户单击确定",则我要继续进入数据的下一页,否则,我想取消编辑,并使用现有编辑将用户保留在当前页面上.我的另一种选择是简单地在分页或排序时自动提交任何更改,或允许它们取消并保留在当前页面上.

I am looking for a way to prompt the user upon attempting a sort or clicking on one of the paging links while there have been edits made on the particular page (as in page of the datagrid/datasource). If the user clicks OK, then I want to continue onto the next page of data, otherwise I would like to cancel the edit and keep the user on the current page with the existing edits. My other option would simply be to automatically commit any changes upon paging or sorting or allow them to cancel and stay on the current page.

到目前为止,我的尝试一直是使用实际网格数据源上的change事件将脏标志存储到可观察标记中,然后尝试通过侦听网格的dataBinding事件并捕获实际的排序或分页更改来显示实际的排序或分页更改.当我的isDirty标志为true且dataBinding事件的e.action =="rebind"时提示.

My attempts thus far have been to use the change event on the actual grid datasource to store a dirty flag into an observable and then try to catch the actual sorting or paging change by listening to the dataBinding event of the grid and display the prompt when my isDirty flag is true and the e.action of the dataBinding event == "rebind".

这种方法的问题在于,在网格dataSource已经执行了另一页的获取之后而不是在其之前触发了dataBinding事件.这样一来,我既无法保存任何编辑内容,也无法保存现有的编辑内容.

The problem that I am having with this approach is that the dataBinding event fires after the grid dataSource has already performed a fetch of another page and not prior. This prevents me from both saving any edits or even maintaining existing edits.

我找不到我可以订阅的任何事件,这使我可以在页面获取/排序之前进行检查.还有其他人想出一种方法来处理这种情况吗?在我看来,这是人们要在数据输入应用程序中处理的非常普遍的事情.

I can't find any event that I can subscribe to that will allow me to do inspections prior to a page fetch/sort. Has anyone else come up with a way to handle this scenario? It seems to me that it would be a pretty common thing that people would want to handle in data entry applications.

推荐答案

我通过订阅dataSource的requestStart事件解决了我的问题.所以现在我的Kendo数据源看起来像这样:

I solved my problem by subscribing to the requestStart event of the dataSource. So now my Kendo Datasource looks like this:

{
    pageSize: 15,
    batch: false,
    schema: {
        model: {
            id: "LocalId",
            fields: {
                LocalId:
                {
                    editable: false,
                    nullable: true
                },
                Ssn: {
                    validation: {
                       required: true
                    }
                },
                QtrEarnings: {
                    type: "number",
                    defaultValue: 0,
                    validation: { required: true, min: 0 }
                }
            }
        }
    },
    change: function (e) {
        onDataChange(e);
    },
    requestStart: function (e) {
        if (homeModel.get("dataSource").hasChanges()) {
            if (confirm("You have made edits to data! Click Cancel to stay on this page or click Ok to abandon your changes and continue.") == false) {

                e.preventDefault();
            }
        }
    }
}

这篇关于如何在更改页面或在Kendo Grid中排序时提示用户已进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆