Kendo 网格 - 项目总数设置不正确(我正在使用 Ajax 调用来填充远程数据)

Kendo Grid - Total number of items are not setting properly ( I am using Ajax call to populate remote data)

我在设置 Kendo 网格的总记录数时遇到奇怪的问题。 我正在根据搜索查询填充网格。结果在提交按钮单击时加载。

网格分页是通过服务器端代码控制的。因此,搜索结果被缩减为结果的子集,检索到的记录数根据为网格设置的页面大小而定。 我还提到了一个获取结果总数的字段。

服务器端执行后,结果以 JSON 格式发回。响应包含结果数据和 TotalRecordCount 。

我正在将结果设置为这样的网格(这有效!) $('#SearchResult').data('kendoGrid').dataSource.data(response.SearchResults) 但问题是,页数总是设置为 1

我尝试显式设置网格数据源的 "total" 属性,

$('#SearchResult').data('kendoGrid').dataSource.total(response.TotalResults) 但这设置不正确

我尝试了不同的方法

 var dataSource = new kendo.data.DataSource({
                            data: response.SearchResults,
                            total: response.TotalRecordNumbers
                        }); 

 var resultGrid = $('#SearchResult').data('kendoGrid');
                        resultGrid.setDataSource(dataSource);//does not work 

我可以填充结果,但问题是由于总数设置不正确,分页不起作用。

非常感谢任何帮助。 谢谢

您必须在架构上设置 'total',而不是数据源本身。

var dataSource = new kendo.data.DataSource({
  transport: {
    /* transport configuration */
  },
  serverGrouping: true,
  schema: {
    total: function(response) {
      return response.total;
    }
  }
});

此示例复制自the official Doku