totalRows should also accept 0 rows
LuisAverhoff opened this issue · comments
8When using pagination in either client side or server side and the number of rows returned is 0, totalRows
is not properly updated to reflect this in the UI. What happens is that totalRows
retains the previously value that it had. This can cause discrepancies in the pagination controls such as the following
Notice how the next button is enabled even though there is no data.
Lastly, notice how it saids 31-40 of 50
when it should probably say 0-0 of 0
.
I propose the following fixes:
@computed('pageSize', 'pageNumber', 'normalizedTotalRows')
get paginationData() {
...
const shouldUpdatePaginationData = typeof totalRows === "number" && totalRows >= 0;
if (shouldUpdatePaginationData ) {
totalPages = Math.ceil(totalRows / pageSize);
pageNumber = Math.min(pageNumber, totalPages);
isLastPage = pageNumber === totalPages;
}
....
if (shouldUpdatePaginationData ) {
pageEnd = Math.min(pageEnd, totalRows);
}
}
There are probably other places in the codebase that treat 0 rows as falsey(like the one above) when more than likely we want to it to execute even when 0 rows were returned so that the UI is properly updated.
the following line in the mirage/config.js
file should be moved to the end after all filtering has been done so that we get the true total number of records that server will be returning.
// add this so we can have this info on the serializer
// This should be done after applying all filters.
request.mirageMeta = { totalRows: records.length };