KoGrid
KoGrid copied to clipboard
Total Items is 1 even if there are no rows
Kogrid will display total items of 1 in the footer even if the number of rows in the grid is 0. I think I have nailed it down to this piece of code:
self.maxRows = ko.observable(Math.max(self.config.pagingOptions.totalServerItems() || self.sortedData().length, 1));
Why is maxRows defaulted to 1?
The value displayed is the computed observable self.maxRowsDisplay
It seems to work if it is changed from:
self.maxRowsDisplay = ko.computed(function () {
return self.maxRows;
});
to
self.maxRowsDisplay = ko.computed(function () {
return Math.max(self.config.pagingOptions.totalServerItems() || self.sortedData().length, 0);
});
I tried the above solution and it didn't work. But changing the 1 to 0 in the math function in the above solution along with changing it in below code worked.
self.maxPages = ko.computed(function () { self.maxRows(Math.max(self.config.pagingOptions.totalServerItems() || self.sortedData().length, 0)); return Math.ceil(self.maxRows() / self.pagingOptions.pageSize()); });
The important question is, making changes in the source file a good idea. That could get overwritten with by the next update.