PDA

View Full Version : Implementing sort on the whole collection for a paginated grid



djitendranath
13 Dec 2012, 9:10 AM
The Grid that I have implemented has pagination. On click of the 'next' button it goes and fetches the next 100 rows. The sort on the Grid is only on each displayed page, when the user clicks the column header.
Is there a way to implement both pagination where I load 100 rows at a time but when the user clicks the column header the whole collection of let's say 900 rows is sorted by that particular column header and the first 100 from that sorted collection is displayed?

I am using com.extjs.gxt.ui.client.widget.grid.Grid and com.extjs.gxt.ui.client.store.ListStore

djitendranath
13 Dec 2012, 9:11 AM
The Grid that I have implemented has pagination. On click of the 'next' button it goes and fetches the next 100 rows. The sort on the Grid is only on each displayed page, when the user clicks the column header.
Is there a way to implement both pagination where I load 100 rows at a time but when the user clicks the column header the whole collection of let's say 900 rows is sorted by that particular column header and the first 100 from that sorted collection is displayed?

I am using com.extjs.gxt.ui.client.widget.grid.Grid and com.extjs.gxt.ui.client.store.ListStore

Any help or direction is much appreciated.

Colin Alworth
13 Dec 2012, 8:46 PM
Merged the two threads - please don't post the exact same thing in several places. The forums aren't just helpful for you learning to use GXT when you ask, they are also handy for people reading past questions, and getting the complete answer in one place to the one question.

When loading from a remote data source (the server), how can the client be able to sort the whole list? It only has your page size (100) on the client at a time. It is the server's job, with all rows (900 in this example) to only send the rows that make sense.

The load config should have data about what page was requested (what offset, how many items), as well was what sort (which column, which direction). It may also have filter information, if you have configured it to. Specify the correct loader to do the work you need.

The server then should read those values out and fetch data accordingly. If you are using SQL, for example, the sort data should go into the ORDER BY clause - then the database will actually give you only what you ask for, in the order it should be in for the sort.

GXT doesn't provide for this feature - it is up to how you are getting the data. If GXT specified exactly how you should store data, we could do this, but that would require GXT being not only widgets, but web server, database, etc. There are many databases and many servers, each with different features and downsides - you should pick the ones that fit the project you are working on.