deep-jade
deep-jade2mo ago

Can I modify the column in useMemo so that I can control it myself?

const columns = React.useMemo<GridColDef<IPointValues>[]>(
() => [
{field: 'id', headerName: 'ID'},
{
field: 'order_id',
flex: 1,
headerName: '주문번호',
minWidth: 150,
},
{
field: 'order_date',
flex: 1,
headerName: '주문일 (결제일)',
minWidth: 200,
renderCell: function render({ row }) {
const orderDate = dayjs(row.order_date).format('YYYY-MM-DD HH:mm:ss');
const paymentDate = dayjs(row.payment_date).format('YYYY-MM-DD HH:mm:ss');
return (
<>
<div>
<span>{orderDate}</span>
<br />
<span>({paymentDate})</span>
</div>
</>
)
},
},
{
field: 'order_status',
flex: 1,
headerName: '주문/CS 상태',
minWidth: 150,
renderCell: ({ value }) => (
<>
<div>
{value.split(',').map((status:string, index:number) => (
<div>
<span>{status.trim()}</span>
</div>
))}
</div>
</>
),
},
{
field: 'member_name',
flex: 1,
headerName: '주문자 / 아이디',
minWidth: 150,
renderCell: function render({ row }) {
const memberName = row.member_name
const memberEmail = row.member_id
return (
<>
<div>
{memberName}
<br />
{memberEmail}
</div>
</>
)
},
},
{
field: 'product_name',
flex: 1,
headerName: '상품명',
minWidth: 300,
},
const columns = React.useMemo<GridColDef<IPointValues>[]>(
() => [
{field: 'id', headerName: 'ID'},
{
field: 'order_id',
flex: 1,
headerName: '주문번호',
minWidth: 150,
},
{
field: 'order_date',
flex: 1,
headerName: '주문일 (결제일)',
minWidth: 200,
renderCell: function render({ row }) {
const orderDate = dayjs(row.order_date).format('YYYY-MM-DD HH:mm:ss');
const paymentDate = dayjs(row.payment_date).format('YYYY-MM-DD HH:mm:ss');
return (
<>
<div>
<span>{orderDate}</span>
<br />
<span>({paymentDate})</span>
</div>
</>
)
},
},
{
field: 'order_status',
flex: 1,
headerName: '주문/CS 상태',
minWidth: 150,
renderCell: ({ value }) => (
<>
<div>
{value.split(',').map((status:string, index:number) => (
<div>
<span>{status.trim()}</span>
</div>
))}
</div>
</>
),
},
{
field: 'member_name',
flex: 1,
headerName: '주문자 / 아이디',
minWidth: 150,
renderCell: function render({ row }) {
const memberName = row.member_name
const memberEmail = row.member_id
return (
<>
<div>
{memberName}
<br />
{memberEmail}
</div>
</>
)
},
},
{
field: 'product_name',
flex: 1,
headerName: '상품명',
minWidth: 300,
},
If the characters become long after using useMemo, they are abbreviated as "..." Can I modify the heat so that I can control it myself?
8 Replies
kapa.ai
kapa.ai2mo ago
Hi @florent. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you can modify the columns in useMemo to control the display of your data. The useMemo hook is used to optimize performance by memoizing the column configuration and preventing unnecessary re-renders. If you want to control the text overflow (the "..." you mentioned), you can use the renderCell property of the column definition. This property allows you to customize how the data in a cell is displayed. You can return a custom component or format the data in a way that suits your needs. Here's an example of how you can modify the product_name field to control the text overflow:
{
field: 'product_name',
flex: 1,
headerName: '상품명',
minWidth: 300,
renderCell: function render({ value }) {
return (
<div style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{value}
</div>
);
},
}
{
field: 'product_name',
flex: 1,
headerName: '상품명',
minWidth: 300,
renderCell: function render({ value }) {
return (
<div style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{value}
</div>
);
},
}
In this example, the renderCell function returns a div with CSS styles that control the text overflow. The whiteSpace: 'nowrap' style prevents the text from wrapping to the next line, overflow: 'hidden' hides the text that exceeds the cell's width, and textOverflow: 'ellipsis' displays an ellipsis ("...") to indicate that there's more text. Please note that this is a simple example and you might need to adjust the styles to fit your specific needs. Sources: - Github Issue (closed): [BUG] Invalid hook calls using the documentation suggested approach for handling data relationships in material-ui datagrid > Comments Part 1 (https://github.com/refinedev/refine/issues/2062) - Documentation > Docs > Ui-integrations > Material-ui > Migration Guide from v4 to v5 > Required Changes > GridColumns to GridColDef[] (https://refine.dev/docs/ui-integrations/material-ui/migration-guide#gridcolumns-to-gridcoldef) - Documentation > Docs > Ui-integrations > Chakra-ui > Introduction > Code Files Part 49 (https://refine.dev/docs/ui-integrations/chakra-ui/introduction) - Blog > Blog > Using Material UI DataGrid component with Refine app > Pagination, Filtering, and Sorting using the useDataGrid hook​ > Filtering​ > Controlled filtering​ Part 1 (https://refine.dev/blog/mui-datagrid-refine#controlled-filtering) - Github Issue (closed): [BUG] deleteOne from mutateDelete Function Not Invoked Correctly in List View When Using Specific Resource Name > Original post Part 8 (https://github.com/refinedev/refine/issues/4840) - Discord support thread: How to draw filter datepicker? > Original post Part 1 (https://discord.com/channels/837692625737613362/1186841908354502747) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1184365192482652173> kapa.ai is still learning and improving, please let us know how it did by reacting below
deep-jade
deep-jade2mo ago
@kapa.ai Is it possible to change the width of the column by adjusting it with the mouse?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, it is possible to adjust the width of the columns by dragging with the mouse in some table libraries, but this feature depends on the specific table library you are using with Refine. For example, if you are using Ant Design's Table component, this feature is not supported out of the box. You would need to implement it yourself or use a third-party library that provides this functionality. On the other hand, if you are using Material-UI's DataGrid component, this feature is supported out of the box. You just need to set the resizable property of the GridColDef to true. Here's an example:
const columns: GridColDef[] = [
{
field: 'id',
headerName: 'ID',
resizable: true,
},
// other columns...
];
const columns: GridColDef[] = [
{
field: 'id',
headerName: 'ID',
resizable: true,
},
// other columns...
];
In this example, the 'ID' column is resizable. You can adjust its width by dragging the edge of the header cell. Please note that the actual implementation might vary depending on the specific requirements of your project and the table library you are using. Sources: - Github Issue (closed): [BUG] Invalid hook calls using the documentation suggested approach for handling data relationships in material-ui datagrid > Comments Part 1 (https://github.com/refinedev/refine/issues/2062) - Documentation > Docs > Ui-integrations > Material-ui > Migration Guide from v4 to v5 > Required Changes > GridColumns to GridColDef[] (https://refine.dev/docs/ui-integrations/material-ui/migration-guide#gridcolumns-to-gridcoldef) - Documentation > Docs > Ui-integrations > Chakra-ui > Introduction > Code Files Part 49 (https://refine.dev/docs/ui-integrations/chakra-ui/introduction) - Blog > Blog > Using Material UI DataGrid component with Refine app > Pagination, Filtering, and Sorting using the useDataGrid hook​ > Filtering​ > Controlled filtering​ Part 1 (https://refine.dev/blog/mui-datagrid-refine#controlled-filtering) - Github Issue (closed): [BUG] deleteOne from mutateDelete Function Not Invoked Correctly in List View When Using Specific Resource Name > Original post Part 8 (https://github.com/refinedev/refine/issues/4840) - Discord support thread: How to draw filter datepicker? > Original post Part 1 (https://discord.com/channels/837692625737613362/1186841908354502747) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1184365192482652173> kapa.ai is still learning and improving, please let us know how it did by reacting below
deep-jade
deep-jade2mo ago
@kapa.ai
const columns = React.useMemo<GridColDef<IPointValues>[]>(
() => [
{field: 'id', headerName: 'ID'},
{
field: 'order_id',
flex: 1,
headerName: '주문번호',
minWidth: 150,
resizable: true,
},
const columns = React.useMemo<GridColDef<IPointValues>[]>(
() => [
{field: 'id', headerName: 'ID'},
{
field: 'order_id',
flex: 1,
headerName: '주문번호',
minWidth: 150,
resizable: true,
},
but resizable not working
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The resizable property is a feature of the Material-UI's DataGrid component. However, it seems like you're using the useTable hook from Refine, which doesn't support the resizable property out of the box. If you want to use resizable columns, you might need to switch to a table library that supports this feature, such as Material-UI's DataGrid. Here's an example of how you can define resizable columns with Material-UI's DataGrid:
import { DataGrid, GridColDef } from '@mui/x-data-grid';

const columns: GridColDef[] = [
{
field: 'id',
headerName: 'ID',
resizable: true,
},
{
field: 'order_id',
headerName: '주문번호',
minWidth: 150,
resizable: true,
},
// other columns...
];

return <DataGrid columns={columns} /* other props */ />;
import { DataGrid, GridColDef } from '@mui/x-data-grid';

const columns: GridColDef[] = [
{
field: 'id',
headerName: 'ID',
resizable: true,
},
{
field: 'order_id',
headerName: '주문번호',
minWidth: 150,
resizable: true,
},
// other columns...
];

return <DataGrid columns={columns} /* other props */ />;
In this example, both the 'ID' and '주문번호' columns are resizable. You can adjust their width by dragging the edge of the header cell. Please note that the actual implementation might vary depending on the specific requirements of your project and the table library you are using. Sources: - Github Issue (closed): [BUG] Invalid hook calls using the documentation suggested approach for handling data relationships in material-ui datagrid > Comments Part 1 (https://github.com/refinedev/refine/issues/2062) - Documentation > Docs > Ui-integrations > Material-ui > Migration Guide from v4 to v5 > Required Changes > GridColumns to GridColDef[] (https://refine.dev/docs/ui-integrations/material-ui/migration-guide#gridcolumns-to-gridcoldef) - Documentation > Docs > Ui-integrations > Chakra-ui > Introduction > Code Files Part 49 (https://refine.dev/docs/ui-integrations/chakra-ui/introduction) - Blog > Blog > Using Material UI DataGrid component with Refine app > Pagination, Filtering, and Sorting using the useDataGrid hook​ > Filtering​ > Controlled filtering​ Part 1 (https://refine.dev/blog/mui-datagrid-refine#controlled-filtering) - Github Issue (closed): [BUG] deleteOne from mutateDelete Function Not Invoked Correctly in List View When Using Specific Resource Name > Original post Part 8 (https://github.com/refinedev/refine/issues/4840) - Discord support thread: How to draw filter datepicker? > Original post Part 1 (https://discord.com/channels/837692625737613362/1186841908354502747) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1184365192482652173> kapa.ai is still learning and improving, please let us know how it did by reacting below