How to Fetch Multiple Records from Multiple Tables with useTable Hook #5504
-
How do you deal with fetching multiple records from two or more tables from the API using the useTable hook instead of useMany? Let's say I have customers and order tables from the providers. Is there a way to tell the useTable to get records from those two tables? type Customers = {
id: number;
customer_name: string;
customer_contact: string;
};
type ServiceType = "Wash" | "Dry" | "Fold" | "Full";
type ServiceStatus = "Undone" | "Washing" | "Drying" | "Folding" | "Done";
type Orders = {
id: number;
customerId: number;
orderDate: Date;
orderLoad: number;
orderWeight: number;
serviceType: ServiceType;
orderSoap: number;
orderFabcon: number;
orderBleach: number;
orderNote: string;
orderStatus: ServiceStatus;
orderIsClaimed: boolean;
inventoryId: number | null;
payableId: number | null;
};
const {
refineCore: {
tableQueryResult: { data: orders },
},
previousPage,
nextPage,
getCanPreviousPage,
getCanNextPage,
getHeaderGroups,
getRowModel,
getColumn,
getAllColumns,
} = useTable({
columns,
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
onColumnVisibilityChange: setColumnVisibility,
onRowSelectionChange: setRowSelection,
state: {
sorting,
columnFilters,
columnVisibility,
rowSelection,
},
}); Here's the provider: <Refine
dataProvider={dataProvider(supabaseClient)}
liveProvider={liveProvider(supabaseClient)}
authProvider={authProvider}
routerProvider={routerBindings}
resources={[
{
name: "orders",
list: "/orders",
create: "/orders/create",
edit: "/orders/edit/:id",
show: "/orders/show/:id",
meta: {
canDelete: true,
},
},
{
name: "customers",
list: "/customers",
create: "/customers/create",
edit: "/customers/edit/:id",
show: "/customers/show/:id",
meta: {
canDelete: true,
},
},
{
name: "inventory",
list: "/inventory",
show: "/inventory/show/:id",
meta: {
canDelete: true,
},
},
]}
options={{
syncWithLocation: true,
warnWhenUnsavedChanges: true,
useNewQueryKeys: true,
projectId: "GmM62Q-BMA8wv-2ddnfk",
}}
>
</Refine> |
Beta Was this translation helpful? Give feedback.
Answered by
BatuhanW
Jan 15, 2024
Replies: 1 comment
Answer selected by
aidrecabrera
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/77818652/5579073