Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PHWYericgarza opened this issue Jun 21, 2024 · 0 comments

Comments

@PHWYericgarza
Copy link

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:

  • Large Filter Sets: GET requests have URL length limitations, which can be problematic when sending many filter parameters. POST requests allow for larger payloads.
  • Security: POST requests are generally considered more secure than GET requests for sending sensitive data.
  • API Design: Some APIs are designed to accept filter parameters in the request body rather than the URL.

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:

  • Error Handling: Enhance the error handling mechanisms to provide clear feedback to users if the POST request fails.
  • Documentation: Update the documentation to clearly explain how to use this new feature and its benefits.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant