Multiple filterable tables in the same page
Is it even possible to have multiple filterable tables in the same screen? I am using next.js with refine and antd. And I need to have sometimes combine tables. When I filter something on one table, the url filters will be replaced if I do it in another one.
For example this is url while filtering first table
/combined-tables?pageSize=10¤t=1&filters[0][field]=name&filters[0][operator]=in&filters[0][value][0]=laptop
And then the second table
/combined-tables?pageSize=10¤t=1&filters[0][field]=name&filters[0][operator]=in&filters[0][value][0]=jane
So, no merged filters.
But another problem here is that they both uses different resources. So I would say they need to have a prefix before filters5 Replies
Hi @fristyr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible to have multiple filterable tables on the same page in refine with Next.js and Ant Design. However, you're encountering a common issue related to how filters are managed when using
syncWithLocation
feature.
The problem you're experiencing is due to the default behavior of useTable
hook when syncWithLocation
is enabled. By default, it replaces the existing filters in the URL when new filters are applied.
To solve this issue and have multiple filterable tables on the same page, you can use the syncWithLocation
feature with custom keys for each table. This approach allows you to maintain separate filter states for each table in the URL.
Here's how you can implement this:
1. Use a unique key for each table's useTable
hook:
2. Apply these props to your respective tables:
This approach will result in URL parameters that look like this:
As you can see, this solves both of your problems:
1. The filters are not replaced, but merged.
2. Each table has its own prefix (table1
and table2
), allowing for different resources.
For more detailed information on this feature, you can refer to the useTable documentation.
Remember to adjust your backend API to handle these prefixed filter parameters correctly.
useTable documentation
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@757638374881493022> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
quickest-silverOP•2mo ago
@kapa.ai Your solution with syncWithLocationOptions looking good, but I don't see syncWithLocationOptions exists in api of useTable hook.
In the docs I see "createLinkForSyncWithLocation", but I do not get it how to use it
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize for the confusion in my previous response. You are correct that
syncWithLocationOptions
is not part of the useTable
hook API. I made a mistake in suggesting that feature. Thank you for bringing this to my attention.
Regarding the createLinkForSyncWithLocation
function, it is indeed part of the useTable
hook, but it's not directly related to solving the issue of multiple filterable tables on the same page. Let me explain its purpose and then provide a more accurate solution to your problem.
The createLinkForSyncWithLocation
function is used to create a URL string that includes the current table state (filters, sorting, pagination) when syncWithLocation
is enabled. It's primarily used internally by the hook and for creating custom links that preserve the table state. Here's an example of how it might be used:
However, this doesn't solve the issue of having multiple filterable tables on the same page.
For your specific problem, I apologize that I don't have a direct solution based on the provided knowledge sources. The current implementation of useTable
with syncWithLocation
doesn't have a built-in way to handle multiple tables with different resources on the same page while preserving all filters in the URL.
A potential workaround might involve:
1. Disabling syncWithLocation
for the tables.
2. Manually managing the URL parameters for each table.
3. Parsing these parameters in your component and passing them to each useTable
call.
However, implementing this would require custom logic that isn't directly supported by refine's current API according to the provided documentation.
I recommend reaching out to the refine community or creating an issue on their GitHub repository to request this feature or get more specific guidance on implementing multiple filterable tables on the same page with different resources.
useTable documentation
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@757638374881493022> Kapa.ai is still learning and improving, please let me know how I did by reacting below.