Introducing interface for DataModel #1038
Open
+203
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When Datagrid is used with common database like data sources, it is common, that receiving total count for paging cost extra one query. When working with REST API datasource it is best practice that response for getting resource collection contains information about total count.
For the purposes of creating query only offset and limit is necessary. The total count is necessary for two reasons. First is to show UI component with list of pages. Second to check if requested page number is not higher that collection maximum.
The problem with current model is, that the order in witch get total count is received cost two calls on Rest API endpoint instead of one. I suggest to move call of getCount() method after getting data. When working with DB, it does not matter if the getCount() call is sooner or later with performance in mind.
I have already created PR #1037 but i`ve change my mind and created this PR.
DataModel now implements interface and Datagrid use interface instead of specific implementation. For purposes of REST based datasources i have created new DataModel where order of getCount method call is changed.
If somebody wants to change datamodel, it can be done with new method
setDataModel
.