【问题标题】:KendoUI grid optimize剑道UI网格优化
【发布时间】:2015-01-07 09:23:14
【问题描述】:

我有两个剑道网格命名:

var sourcegrid = $('#usersGrid').data("kendoGrid");        //SOURCE GRID
var destinationgrid = $('#teamGrid').data('kendoGrid');    //DESTINATION GRID

在 sourcegrid 中我有 1000 条记录,而在destinationgrid 中没有记录。

我有将数据从源网格传输到目标网格的按钮。

代码:

 sourcegrid.select().each(function () {
        var dataItem = sourcegrid.dataItem($(this));
        destinationgrid.dataSource.add(dataItem);
        sourcegrid.removeRow($(this));
    });

当我将 500 条记录传输到destinationgrid 时。转移的过程是这样的 慢的。任何优化它的想法。

谢谢

你可以编辑这个 http://jsfiddle.net/2qXKy/112/

【问题讨论】:

标签: jquery optimization kendo-ui kendo-grid kendo-asp.net-mvc


【解决方案1】:

这是我为您加快速度的尝试:

http://jsfiddle.net/5t5c2g1y/2/

var ds1 = new kendo.data.DataSource( {
    data: createRandomData(500),
    scrollable: true,
    schema: {
        model: {
            id: "id",
            fields: {
                id: {
                    type: 'number',
                    editable: true
                },
                FirstName: {
                    type: 'string',
                    editable: true
                },
                LastName: {
                    type: 'string',
                    editable: true
                }
            }
        }
    }
});

var ds2 = new kendo.data.DataSource({
    data: createRandomData(0),
    scrollable: true,
    schema: {
        model: {
            id: "id",
            fields: {
                id: {
                    type: 'number',
                    editable: true
                },
                FirstName: {
                    type: 'string',
                    editable: true
                },
                LastName: {
                    type: 'string',
                    editable: true
                }
            }
        }
    }
});

var sourcegrid = $("#usersGrid").kendoGrid({
    dataSource: ds1,
    editable: "popup",
    selectable: "multiple",
    pageable: false,
    columns: [{
        field: "FirstName",
        width: 90,
        title: "First Name"
    }, {
        field: "LastName",
        width: 90,
        title: "Last Name"
    }]
}).data("kendoGrid");

var destinationgrid = $("#teamGrid").kendoGrid({
    dataSource: ds2,
    editable: "popup",
    selectable: "multiple",
    pageable: false,
    columns: [{
        field: "FirstName",
        width: 90,
        title: "First Name"
    }, {
        field: "LastName",
        width: 90,
        title: "Last Name"
    }]
}).data("kendoGrid");


$('input[type=button]').on('click',function() {
    var removalList = []; 
    sourcegrid.select().each(function () {

        var dataItem = sourcegrid.dataItem($(this));
        console.log(dataItem);
        removalList.push(dataItem)
        ds2.add(dataItem);


    });

   for(var i = 0; i< removalList.length;i++)
   {
       ds1.remove(removalList[i]);
   }

});

如果您与数据源而不是网格本身进行交互,您希望看到该过程要快得多(加上摆脱要求您确认删除的弹出消息)

您会注意到我添加了一个控制台语句,以便您可以看到正在复制的信息。

再次希望这会有所帮助。

【讨论】:

  • 感谢 David Shorthose。选择所有记录并将其传递给destinationgrid时的另一个问题。它挂起/停止。比如响应的秒数
  • 我猜这取决于你机器的速度。您可以在进行复制时向屏幕/进度条添加注释。但我发现在进行完整复制时大约需要 10 - 20 秒。
  • 您可以为完整副本做的一件事是查看所选行数是否与数据源中的行数相同,然后将整个数据源复制到第二个并清除第一个数据源,而不是复制单个行。
  • 很好的建议将所有数据源复制到destinationgrid并清除。如果未选择某些记录如何执行。任何建议或解决方法来加快传输记录
  • 另一种方法是通过某种服务器端技术来做到这一点,只需将 id 传回以使行移动和刷新,而不是尝试在客户端进行所有操作。我假设您会将其保存回某种形式的数据库,因此最好在那里进行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 2013-10-07
  • 2013-09-24
  • 2015-11-11
  • 2014-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多