Syncwithlocation
how to achieve Syncwithlocation with useList like useTable, or if it's not supported, what's the cleanest way to make my own Syncwithlocation
useTable. This feature allows the state of the list or table (such as sort order, filters, and pagination) to be automatically encoded in the URL's query parameters. When the URL changes, the state of the list or table is automatically updated to match. This makes it easy to share list states across different routes or pages and allows users to bookmark or share links to specific table views.true as shown in the example below:false by default. You can also set this value globally on the component.useTable, you can refer to the useTable documentation as suggested in a GitHub issue comment.true, the URL will reflect the current state of your page.field is , the is , and the value is .field, , and value properties.syncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationsyncWithLocationuseSimpleListuseSimpleList<Refine>sortersortersgetListuseListuseListuseListfilters[0][field]=status.text&filters[0][operator]=in&filters[0][value][0]=Readystatus.textoperatoroperatorinReadyURLSearchParamsURLSearchParamsURLSearchParamsfiltersfiltersfiltersqueryStringqueryString"filters[0][field]=status.text&filters[0][operator]=in&filters[0][value][0]=Ready""filters[0][field]=status.text&filters[0][operator]=in&filters[0][value][0]=Ready"filters=filters%255B0%255D%255Bfield%255D%3Dcolor%26filters%255B0%255D%255Boperator%255D%3Deq%26filters%255B0%255D%255Bvalue%255D%3Deb1d7435-69be-4a85-9753-a9109252d820%255B%5B[%255D%5D]%3D=%26&useSimpleList({
syncWithLocation: true,
}); const params = new URLSearchParams(window.location.search);
const filters = JSON.parse(params.get('filters'));const filters = [
{
field: "status.text",
operator: "in",
value: ["Ready"],
},
// more filters...
];
const params = new URLSearchParams();
filters.forEach((filter, index) => {
params.append(`filters[${index}][field]`, filter.field);
params.append(`filters[${index}][operator]`, filter.operator);
if (Array.isArray(filter.value)) {
filter.value.forEach((value, valueIndex) => {
params.append(`filters[${index}][value][${valueIndex}]`, value);
});
} else {
params.append(`filters[${index}][value]`, filter.value);
}
});
const queryString = params.toString();const filters = [
{
field: "status.text",
operator: "in",
value: ["Ready"],
},
// more filters...
];
const params = new URLSearchParams();
filters.forEach((filter, index) => {
params.append(`filters[${index}][field]`, filter.field);
params.append(`filters[${index}][operator]`, filter.operator);
if (Array.isArray(filter.value)) {
filter.value.forEach((value, valueIndex) => {
params.append(`filters[${index}][value][${valueIndex}]`, value);
});
} else {
params.append(`filters[${index}][value]`, filter.value);
}
});
const queryString = params.toString();