Server-side pagination requests each page individually loaded upon navigation. The server needs to support pagination, and then the client side can request data sets with specified page sizes, page index, and possibly sorting orders and filtering criteria. The server responds with the appropriate subset. Server-side pagination handles a large amount of data and provides stability and scalability.
Advantages of Server-Side Pagination
- Can Handle Large data sets.
- Faster initial page load.
- Improve page load time with minimized network latency
In Mendix Server Side pagination can be achieved using Data Grids either with Data grid 1 or Data grid 2. This blog will show how to achieve server-side pagination via Data Grid 1.
Steps to implement in the Data grid 1:
- Create a Microflow with retrieve activity from the database or from the association as shown in the image below. This retrieves what data that needs to be shown in the grid. You can customize the number of data that needs to be displayed on the grid later.
- After Creating the microflow for retrieving the data then select the data grid from the toolbox and paste it into the UI/Page. As shown in the picture below by default, it will throw an error. To resolve that we need to select the data source.
- Now select the data source as microflow which we have created earlier.
- After selecting the microflow the page will ask for the following option to generate the controls for server-side pagination and Select Yes.
- This will create all the necessary nanoflows and pagination controls as shown in the picture below.
- After this the module will throw an error in the error list.
- To resolve this, we need to modify our microflow which we created earlier. We need to set up the return list of the data to List.
- Now we need to specify how much data that needs to be loaded into the page. This can be done in the retrieve option where we can specify the number of data that needs to be loaded in the grid per page.
- Then we need to specify the offset. The offset can be specified as follows. The number 20 represents how much data that needs to be loaded per page.
After completing all the steps, sever side pagination is ready for use.
Challenges Faced During Implementation:
While implementing the server-side pagination we faced some challenges. The challenges are as follows:
- We are retrieving the data per page from the microflow. So, we won’t be able to know how much data is left to load since we are not retrieving the entire database.
- To overcome the above limitation, while loading the page itself we have calculated the count using Aggregate list operations.
- Also, there won’t be any navigation button for jumping to the last page of the grid. This we need to create manually by calculating the total no of data in the data source and with the help of the total no of data, we can calculate the total number of pages in the grid.
- If you are using Advanced Search or any filter options, then whenever we are using that we need to redirect the page of the grid to first page.
Please see the part 2 : Server-Side Pagination in Mendix (Data Grid 2)