简体   繁体   English

获取Kendo Grid过滤的数据源计数

[英]Get Kendo Grid filtered datasource count

I'm using tool bar filter Dropdown in kendo grid. 我在kendo网格中使用工具栏过滤器Dropdown。 When user selects the dropdown I need to get the count of filtered records. 当用户选择下拉列表时,我需要获取已过滤记录的计数。 Below code is not working for me 下面的代码不适合我

function ExamDateChange() { // function on dropdown change
        var value = this.value(),
             grid = $("#grid").data("kendoGrid");

        if (value) {
            grid.dataSource.filter({ field: "ExamID", operator: "eq", value: value });

            grid.dataSource.fetch(function () {
                var view = dataSource.view();
                alert(view.length); 

            });

        } else {

            grid.dataSource.filter({});
        }


    }

You might use fetch but instead of using dataSource.view().length you should use dataSource.total() method. 您可以使用fetch,但不要使用dataSource.view().length您应该使用dataSource.total()方法。

Something like: 就像是:

function ExamDateChange() { // function on dropdown change
    var value = this.value(),
        grid = $("#grid").data("kendoGrid");    
    if (value) {
        grid.dataSource.filter({ field: "ExamID", operator: "eq", value: value });
        grid.dataSource.fetch(function () {
            alert(view.dataSource.total()); 
        });
    } else {
        grid.dataSource.filter({});
    }
}

See it in action here: http://jsfiddle.net/OnaBai/f19k0vrt/5/ Type two dates and click "Filter" button and it will apply the filter on Birth Date and show you the total. 请在此处查看: http//jsfiddle.net/OnaBai/f19k0vrt/5/键入两个日期,然后单击“过滤”按钮,它将在出生日期应用过滤器并显示总计。

Okay here we go, 好的,我们走了,
i tried also the chage event from the dropdown but it doesnt work as you said. 我也尝试了下拉列表中的chage事件,但它并没有像你说的那样工作。 The event is called before the dataSource of the Grid is set. 在设置Grid的dataSource之前调用该事件。

So I think we need the callback when Grids dataSource is bound, so thaht the dataBound event from the Grid. 所以我认为在绑定Grids dataSource时需要回调,因此来自Grid的dataBound事件。

...
dataBound: function(){
    console.log("Grid data bound");   
    // this should do the trick    
    alert(grid.data("kendoGrid").dataSource.data().length);
},
...

Here is a rudimental fiddle of that. 这是一个基本的小提琴
I hope this is what you need. 我希望这就是你所需要的。

Update: 更新:
In the case you use serverpaging, you could use the requestEnd event from the datasource. 在使用serverpaging的情况下,您可以使用数据源中的requestEnd事件。
You have to look up the server response. 您必须查找服务器响应。 In the fiddle you got a "__count" property. 在小提琴中你得到了一个“__count”属性。
Updated fiddle 更新了小提琴

...
requestEnd: function (e) {
    var response = e.response;
    var type = e.type;
    alert(response.d.__count); // displays "77"
},
...

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

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