grid-js / gridjs

Advanced table plugin
https://gridjs.io
MIT License
4.39k stars 240 forks source link

Feature Request: Server-Side Pagination with POST and Additional Filtering Fields #1457

Open PHWYericgarza opened 3 months ago

PHWYericgarza commented 3 months ago

Description:

Currently, Grid.js primarily supports server-side pagination using GET requests, where parameters like prev, page, limit are appended to the URL. However, there are scenarios where using POST requests would be advantageous:

Proposed Enhancement:

I propose adding an option to the pagination.server configuration to allow using POST requests for pagination. This would involve:

  1. method: 'POST': Allow setting the HTTP method to 'POST'.
  2. body Function: Allow defining a body function that would be called for each pagination request. This function would receive the config object (containing page, pageSize, etc.) and could include additional fields for filtering.
  3. Consistent Body Format: Ensure that the body function in the main server configuration (for initial data loading) and the pagination.server configuration (for pagination requests) can have the same structure for consistency.

Example Code:

const grid = new Grid({
    // ... columns
    server: {
        method: 'POST',
        url: '/api/v1/getdata',
        headers: {
            'Content-Type': 'application/json'
        },
        body: (config) => JSON.stringify({
            Page: config.page + 1,
            PageSize: config.pageSize,
            Field1: 'value1',
            Field2: 'value2'
        }),
        then: (data) => data.data,
        total: (data) => data.total
    },
    pagination: {
        limit: 10,
        server: true 
    }
});

Justification:

This enhancement would make Grid.js more versatile and adaptable to different backend API designs. It would address the limitations of GET requests and provide a more secure way to send filter parameters.

Additional Considerations:

I hope this feature request is helpful! Let me know if you have any other questions or would like to refine it further.