national-gold
national-gold8h ago

useExport only items showing on the list.

Basically I want to export only the items the user can see on the list.
5 Replies
kapa.ai
kapa.ai8h ago
Hi @khadhulu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To export only the items currently visible to the user on the list (i.e., those matching the current filters, sorters, and pagination), you should pass the same filters, sorters, and pagination parameters used in your list view to the useExport hook. The useExport hook supports filters and sorters, which are passed to your data provider’s getList method. This means you can export only the filtered and sorted data, not necessarily the entire resource. For example:
const { filters, sorters, pagination } = useList({
resource: "products",
// ...other list options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
// Optionally, you can use pagination to export only the current page
pagination,
});
const { filters, sorters, pagination } = useList({
resource: "products",
// ...other list options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
// Optionally, you can use pagination to export only the current page
pagination,
});
However, by default, useExport is designed to export all data matching the provided filters and sorters, not just the current page. If you want to export only the items on the current page (i.e., what the user sees), you should also pass the current pagination state (current page and page size) to useExport. This will limit the export to just those items. Here’s an example of how to use filters, sorters, and pagination with useExport:
import { useList, useExport } from "@refinedev/core";

const { filters, sorters, pagination } = useList({
resource: "products",
// ...other list options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
pagination, // This limits export to the current page
});
import { useList, useExport } from "@refinedev/core";

const { filters, sorters, pagination } = useList({
resource: "products",
// ...other list options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
pagination, // This limits export to the current page
});
Important:
- If you omit pagination, useExport will export all items matching the filters and sorters, not just the current page. - If you want to export only the current page, make sure to pass the pagination object as well. For more details, see the documentation on the useExport hook and its properties, especially the filters, sorters, and pagination options: useExport Properties. Note:
If you want to export exactly what is visible (including any client-side modifications or selections), you may need to map the currently displayed data directly, but the standard approach is to use the same server-side parameters as your list view. If you need to export only a subset of the filtered data (e.g., selected rows), this is not directly covered in the knowledge sources and may require custom logic. References:
- useExport Properties - CSV Import - Export Guide - Data Fetching: Filters, Sorters, and Pagination ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8h ago
<@236239059184386048> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
national-gold
national-goldOP8h ago
@kapa.ai how can I do it with useTable?
kapa.ai
kapa.ai8h ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To export only the items currently visible in your list when using useTable, you should pass the current filters, sorters, and pagination state from useTable to useExport. The useTable hook provides these states as return values: filters, sorters, currentPage, and pageSize. However, the knowledge sources confirm that useExport supports filters and sorters, but they do not explicitly mention a pagination option. By default, useExport will export all items matching the filters and sorters, not just the current page. If you want to export only the current page (i.e., what the user sees), you need to manually construct the filters and sorters from useTable and limit the export to the current page by slicing the data after fetching, since useExport does not natively support a pagination parameter. Here’s how you can use useTable together with useExport to export only the filtered and sorted data (not paginated):
import { useTable, useExport } from "@refinedev/core";

const { filters, sorters } = useTable({
resource: "products",
// ...other options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
});
import { useTable, useExport } from "@refinedev/core";

const { filters, sorters } = useTable({
resource: "products",
// ...other options
});

const { triggerExport } = useExport({
resource: "products",
filters,
sorters,
});
If you want to export only the items on the current page, you would need to fetch the current page's data yourself (using the result from useTable) and then create a CSV from that data, since useExport does not support pagination directly according to the documentation and knowledge sources provided useExport Properties. Summary:
- You can export filtered and sorted data by passing filters and sorters from useTable to useExport. - Exporting only the current page (pagination) is not directly supported by useExport; you would need to handle this manually. If you need to export only the visible page, you may need to implement a custom export function using the data from useTable’s result property. References:
- useExport Properties - useTable Return Values ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8h ago
<@236239059184386048> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?