【问题标题】:Display the count of total number of records in the grid显示网格中记录的总数
【发布时间】:2018-08-26 21:50:10
【问题描述】:

我正在尝试显示网格中记录的总数。 我使用了下面的代码,但它不起作用。

你能告诉我如何解决它。

这是我的代码

http://jsfiddle.net/cynmp0s3/

  var grid = $("#grid1").data("kendoGrid");
  console.log("grid" + JSON.stringify(grid));
  var dataSource = grid.dataSource;
  alert("dataSource", dataSource);

  var count = grid.dataSource.total();
  alert("count", count);


  //records on current view / page   
  var recordsOnCurrentView = dataSource.view().length;
  alert("recordsOnCurrentView", recordsOnCurrentView);

  //total records
  var totalRecords = dataSource.total();
  alert("totalRecords", totalRecords);

【问题讨论】:

  • 您的小提琴涉及的方面太多,无法真正了解您想让我们检查的内容。我不知道哪个按钮有什么作用,我也懒得弄明白。尝试将您的代码简化为问题。
  • @A.Lau 嘿,当在名字文本字段中输入一些值并点击 go...您将看到网格,对于该网格,它应该显示记录总数
  • 完善它。 console.log 也更好,因为您不必连续点击 ok 来获取下一个信息。
  • @A.Lau 嘿,现在删除警报并更改 if 条件
  • @arkr 您无法在调用加载后访问数据源中的记录总数。他们需要时间来加载。您是否考虑过可用时间?

标签: javascript jquery html css kendo-ui


【解决方案1】:

在网格的dataBound事件中获取数据源的长度。

$("#grid1").kendoGrid({
    dataSource: ds1,
    height: 180,
    scrollable: {
      virtual: true
    },
    columns: [{
        field: "codeLong",
        title: "codeLong"
      },
      {
        field: "codeShort",
        title: "codeShort"
      },
      {
        field: "name",
        title: "name"
      }

    ],
    dataBound: function(e){
        alert("totalRecords "+e.sender.dataSource._data.length);
    }
  });

【讨论】:

    猜你喜欢
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 2018-11-02
    • 1970-01-01
    相关资源
    最近更新 更多