Best way to show a nested object inside a datagrid #1419
-
I want to do this but in Toolpad. It has nested object and is easier to add in the table the pro-code way. In Toolpad, I am expected to first transform the nested object to a basic object. My question is: As nested objects are quite common in big data sets. Is transformation the best way to handle it? Or, like pro-code can we have table cell abstractions inside the Table row as well? It will remove the need to write unnecessary transformation code. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I can't seem to understand what the requirement is since it only seems to show this: |
Beta Was this translation helpful? Give feedback.
-
This might be too late, but I think it's still worth answering the question :) There's one more way of dealing with nested data - you can use const columns = [
{
field: "companyName",
valueGetter: ({ row }) => row.data.company.name,
}
] If you want to also make the column editable - you will need to provide const columns = [
{
field: "companyName",
editable: true,
valueGetter: ({ row }) => row.data.company.name,
valueSetter: ({ row, value }) => {
return {
...row,
data: {
...row.data,
company: {
...row.data.company,
name: value,
}
}
}
}
}
] Here's a demo using Hope this answers the question, let me know if there are any questions left :) |
Beta Was this translation helpful? Give feedback.
I would think that a transform on the query is the best way to accomplish this.
I think we could at some point even auto-suggest the transformation code instead of writing a lot more code to build UI to accomplish tasks that could be done via a single-line of transformation code.