Okay
  Public Ticket #3811605
Filter issues
Open

Comments

  • Jim started the conversation

    Subject: Assistance Needed: Filtering wpDataTables Using Date, User Role, and User ID

    Dear wpDataTables Support Team,

    We have been working on implementing dynamic filtering for a table in wpDataTables, but we’ve encountered significant challenges. Here's a summary of our requirements and the issues we’re facing:

    Setup Details:

    • The table in question is based on an SQL query.
    • The table is displayed using wpDataTables (ID: 7).
    • We need to filter the data dynamically using:
      1. A date range (start_date and end_date).
      2. The logged-in user’s role.
      3. The logged-in user’s ID.

    What We’ve Tried:

    1. Using the URL parameters approach (e.g., adding ?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD to filter).
      • While this partially works for simple filters, it’s not integrating well with the dynamic date range and user-specific parameters.
    2. JavaScript for frontend filtering.
      • We tried applying filters via JavaScript by targeting the wpDataTable instance, but it didn’t seem to trigger or reload the filtered data as expected.
    3. Hook-based server-side filtering.
      • We attempted using hooks such as wpdatatables_filter_data_before_display, but there were inconsistencies in passing dynamic data like user role or ID, especially for date ranges selected on the frontend.

    Current Situation: The table renders correctly, but:

    • The dynamic date range filter doesn’t work as expected.
    • User role and ID-based filtering are not applied consistently.
    • We’re unsure of the best method to implement a robust solution that combines these three filtering parameters.

    Our Goal: We need a clear and efficient way to:

    1. Dynamically filter the table based on a date range selected on the frontend (via dropdown or date picker).
    2. Apply server-side filters to ensure that data is displayed according to the logged-in user’s role and user ID.
    3. Combine these filters seamlessly so the table updates correctly without requiring a page reload.

    Could you please guide us on how to achieve this? If there’s a recommended method, example code, or best practice for such scenarios, we would appreciate your help.

    Thank you for your assistance!

    Best regards, Mr Jim

  •   Miloš replied privately