简体   繁体   English

更改 Kendo 网格中的数据太慢

[英]Changing the data within a Kendo grid is too slow

I have a kendo grid that displays between 4000-6000 rows, with 7 columns, and is able to be filtered by the user to only show data within user defined date range.我有一个剑道网格,显示 4000-6000 行,有 7 列,并且能够被用户过滤以仅显示用户定义的日期范围内的数据。 This grid is not updating with new data, but instead is only showing a subset of the full dataset that is retrieved at initialization.此网格不会使用新数据进行更新,而是仅显示在初始化时检索到的完整数据集的子集。 When I change which subset is being displayed, there is a very noticeable 5 second pause.当我更改正在显示的子集时,会出现非常明显的 5 秒停顿。 I am wondering if there is a more efficient way I could change the data , as I know of programs that use Kendo Grid to display 10,000s of rows with much better performance.我想知道是否有更有效的方法可以更改数据,因为我知道使用 Kendo Grid 以更好的性能显示 10,000 行的程序。

This is the code I am using to update the grid.这是我用来更新网格的代码。 The first four lines create an array of data, and then I call the dataSource.data() function to place it into the grid.前四行创建了一个数据数组,然后我调用 dataSource.data() function 将其放入网格中。 This causes my date formatting in the kendo grid to reset, so I then redefine the columns within the options of the kendo grid.这会导致我在剑道网格中的日期格式重置,因此我重新定义了剑道网格选项中的列。

//Create new data array based o nthe user defined date range
    let x = chart.scales["x-axis-0"];
    var min = new Date(x.min);
    var max = new Date(x.max);
    var newData = vm.createDataArrayAtDates(min, max)

//place data into the kendo datasource object
    grid = $("#grid").data("kendoGrid");
    data = grid.dataSource.data(newData);

//redefine the columns of the kendo grid
    var options = grid.getOptions();
    options.columns = vm.createGridColumns();
    grid.setOptions(options);

I have found a way to improve the performance of my kendo grid (which also improved everything else on the page).我找到了一种方法来提高我的剑道网格的性能(这也改进了页面上的其他所有内容)。 To do this, I enabled "Virtual Scrolling" within the kendo grid.为此,我在剑道网格中启用了“虚拟滚动”。 Turning on this feature changed the 5 second delay into a 5 millisecond delay!开启此功能将 5 秒延迟变为 5 毫秒延迟!

Here is a link to the telerik page on virtual scrolling: https://www.telerik.com/kendo-angular-ui/components/grid/scroll-modes/virtual/这是 telerik 虚拟滚动页面的链接: https://www.telerik.com/kendo-angular-modes/uals/grid/virsc/

Here is my implementation:这是我的实现:

          vm.kendoGrid = $(document).ready(function () {
                    $("#grid").kendoGrid({
                        dataSource: vm.createDataSource(),
                        type: "odata",
                        sortable: true,
                        scrollable: {
                            virtual: true
                        },
                        filterable: {
                            extra: false
                        },
                        columns: vm.createGridColumns(),
                        height: 450
                    })
                });

The specific lines that are required for virtual scrolling I have copied below:我在下面复制了虚拟滚动所需的特定行:

sortable: true,
scrollable: {
    virtual: true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM