correct-apricot
correct-apricot15mo ago

(ListInferencer/Antd) Nested Resource Data

Hi! I have data fetched from the API structured like so; { 1: [ {...},{...} ], 2: [ {...} ], 3: [ {...}, {...}, {...} ] } where each key-value pair maps a userID to a list of their tasks for the day -- individually structured like {task: "Wash the dishes", startBy: "May 15, 2023", done: "false"}. The inferencer doesn't like that (TypeError: L.map is not a function) so I'm wondering how I should go about formatting this? I'd like to use either ant.designs nested tables (https://ant.design/components/table#components-table-demo-nested-table) (pictured) or just have several separate tables with a header and use .map(), but its not immediately obvious to me how to do that with Antd's table format (since it's going column-wise rather than row-wise). Any insight would be appreciated!
Table - Ant Design
An enterprise-class UI design language and React UI library with a set of high-quality React components, one of best React UI library for enterprises
No description
18 Replies
kapa.ai
kapa.ai15mo ago
Hi @avangeous. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, I can guide you on how to use Ant Design's <Table> component with refine. Refine uses Ant Design's <Table> component to render data from an API, row by row, as a table. The <Table> component simplifies the workflow and integrates well with refine. Functionalities such as pagination and routing are implemented out of the box. You can use the useTable hook to fetch data from your endpoint and pass its value to the Table component via the tableprops property. Then you set unique keys for each record from the API using the rowkey prop. Here is an example of how to use it:
import React from "react";
import { List, Table, useTable, Space, EditButton } from "@refinedev/antd";

interface IFormValue {
name: string;
email: string;
skills: string;
id: number;
}

export default function PostList() {
const { tableProps } = useTable<IFormValue>();

return (
<List>
<Table {...tableProps} rowKey="id">
<Table.Column dataIndex="firstName" title="First Name" />
<Table.Column dataIndex="email" title="Email" />
<Table.Column dataIndex="skills" title="Skills" />
</Table>
</List>
);
}
import React from "react";
import { List, Table, useTable, Space, EditButton } from "@refinedev/antd";

interface IFormValue {
name: string;
email: string;
skills: string;
id: number;
}

export default function PostList() {
const { tableProps } = useTable<IFormValue>();

return (
<List>
<Table {...tableProps} rowKey="id">
<Table.Column dataIndex="firstName" title="First Name" />
<Table.Column dataIndex="email" title="Email" />
<Table.Column dataIndex="skills" title="Skills" />
</Table>
</List>
);
}
In this example, useTable is a refine hook that fetches data from an API and wraps it with various helper hooks that make it compatible with Ant's <Table> component. For more detailed information, you can refer to the refine documentation (https://refine.dev/docs/api-reference/core/hooks/useTable) and this blog post (https://refine.dev/blog/react-crud-app-with-dynamic-form-ant-design). As for your specific data structure and the error you're encountering, it might be best to consult the Ant Design documentation or community for more specific guidance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai15mo ago
<@1122927158348763206> kapa.ai is still learning and improving, please let us how it did by reacting below
correct-apricot
correct-apricot15mo ago
@kapa.ai Any information on nested tables?
kapa.ai
kapa.ai15mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry, but the provided extracts do not contain specific information on how to implement nested tables with refine and Ant Design's <Table> component. However, refine uses Ant Design's <Table> component for rendering data, and it's compatible with all the features of Ant Design's <Table> component, including nested tables. You might want to refer to the Ant Design's official documentation (https://ant.design/components/table#components-table-demo-nested-table) for more specific guidance on implementing nested tables. For more information on how to use the <Table> component with refine, you can refer to the refine documentation (https://refine.dev/docs/api-reference/antd/hooks/table/useTable) and this blog post (https://refine.dev/blog/react-crud-app-with-dynamic-form-ant-design). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai15mo ago
<@1122927158348763206> kapa.ai is still learning and improving, please let us how it did by reacting below
correct-apricot
correct-apricot15mo ago
@kapa.ai How can I use array.map() with the fetched resource data?
kapa.ai
kapa.ai15mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- You can use the array.map() function with the fetched resource data in refine by using the useList hook. The useList hook fetches data from the API and returns it in a format that can be easily manipulated with JavaScript array methods like map. Here's an example of how you can use array.map() with the fetched data:
import React from "react";
import { useList } from "@refinedev/core";

function useData() {
// Fetching data from the products endpoint using refine's useList hook
const { data } = useList<IProduct>({
config: {
pagination: {
current: 2,
},
},
resource: "products",
});

// Modifying fetched data and adding column property using array.map()
const newArr = data?.data.map((i: IProduct) => {
return {
...i,
column: ColumnTypes.ORDERS,
};
});

return [newArr, data?.data];
}

export default useData;
import React from "react";
import { useList } from "@refinedev/core";

function useData() {
// Fetching data from the products endpoint using refine's useList hook
const { data } = useList<IProduct>({
config: {
pagination: {
current: 2,
},
},
resource: "products",
});

// Modifying fetched data and adding column property using array.map()
const newArr = data?.data.map((i: IProduct) => {
return {
...i,
column: ColumnTypes.ORDERS,
};
});

return [newArr, data?.data];
}

export default useData;
In this example, useList is used to fetch data from the "products" endpoint. The returned data array is then modified using the map method, and a column property is added to each object in the array. For more information, you can refer to this blog post (https://refine.dev/blog/react-draggable-components-with-react-dnd) and the refine documentation (https://refine.dev/docs/api-reference/core/hooks/data/useList). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai15mo ago
<@1122927158348763206> kapa.ai is still learning and improving, please let us how it did by reacting below
correct-apricot
correct-apricot15mo ago
(semi-solved) I just removed the nesting API-side and made two calls a la the finefoods example on github, but i'd still like to know if its possible to deal with nested data in general
fair-rose
fair-rose15mo ago
@avangeous By nested data do you mean when you show one resource it shows a list of your other resources connected to it? I was stumped on this issue FOREVER and finally got it working, if you would like some reference code.
correct-apricot
correct-apricot15mo ago
nah, moreso nested data inside of a resource, i.e key-value pair where value is another dataset. curious what you mean by connected resources though?
fair-rose
fair-rose15mo ago
@avangeous When the resources have database associations, I dont think my use case fits yours then, I read the title and assumed you were trying to show a list of resources below another that is displayed.
correct-apricot
correct-apricot15mo ago
oh i see, like a list of products on a particular store's 'show' page ?
correct-apricot
correct-apricot15mo ago
i have something similar if so; this example is pretty useful https://github.com/refinedev/refine/tree/master/examples/finefoods-antd
GitHub
refine/examples/finefoods-antd at master · refinedev/refine
Build your React-based CRUD applications, without constraints. 🌟 Star to support our work! - refine/examples/finefoods-antd at master · refinedev/refine
correct-apricot
correct-apricot15mo ago