Reputation: 12711
I'm using tool bar filter Dropdown in kendo grid. 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({});
}
}
Upvotes: 1
Views: 9045
Reputation: 40887
You might use fetch but instead of using dataSource.view().length
you should use dataSource.total()
method.
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.
Upvotes: 3
Reputation: 4867
Okay here we go,
i tried also the chage event from the dropdown but it doesnt work as you said.
The event is called before the dataSource of the Grid is set.
So I think we need the callback when Grids dataSource is bound, so thaht the dataBound event from the Grid.
...
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.
You have to look up the server response. In the fiddle you got a "__count" property.
Updated fiddle
...
requestEnd: function (e) {
var response = e.response;
var type = e.type;
alert(response.d.__count); // displays "77"
},
...
Upvotes: 2