Open serenamorena opened 5 years ago
I might be missing something, but it doesn't look like you have any values to map over in your custom render function, if the data you're passing in is schools
. I might need to see the whole running example in a codesandbox.
Also, are you saying that the example doesn't work for you when you run it locally? If so, that sounds like you're version is incorrect, as I do not experience this issue.
I ended up looking into this more deeply in https://github.com/gregnb/mui-datatables/issues/915 and didn't realize the two were related until just now. As you can see in that issue, object data for cells isn't supported right now in any capacity except if you use the dot notation in the column name option to specify which property you want. Otherwise, you can't use objects.
Changing the table to allow this I think will be too big a task for the short term, though if anyone has a proposal for how to handle this, I'd be willing to look over it. I think it would raise a lot of weird UX issues though.
Ok so supporting object data in cells directly is not possible for now, but what about custom search and filter options for columns? A simple array of strings should be sufficient.
@dvdgsng Any time you have access to a custom render, you can use any data you like, as long you pass an identifier as the official table data and link it to whatever object you want outside of the table. It's not as convenient, but I've used this approach myself and I think it's a pretty good workaround.
Using a custom render like below will show the values of foo.bar
's properly, but they will not be searchable.
<MUIDataTable
columns={[
{
name: "foo",
label: "the foos",
options: {
customBodyRender: value => value.map(foo => foo.bar)
}
}
]}
...
Am I missing something here?
@dvdgsng You also have access to custom search and filter options. I don't have a good handle on exactly what you're trying to do, so I'm not sure how exactly to help. Is your issue related to the one opened here?
Are we able to filter objects as of recent like how this does it import MaterialTable from "@material-table/core";
ever since i started using this component import MUIDataTable from "mui-datatables"; my life has become misearable yet i thought its an advancement of @material-table/core
first and foremost that row data of this mui-datatables in customBodyRender: (value, tableMeta) => { console.log("🚀 ~ ListPage ~ tableMeta:", tableMeta); // const tableRowData = { ...(tableMeta.rowData ?? []) };
there returns wiredly it returns as an array instead of object since my initial table data is array of objects
and also
i cant pass in data with children which are array of objects
{ name: "vendor", label: "Vendor", options: { filter: true, sort: true, customBodyRender: (value) => { const vendor = value.name; return <div>{vendor ? vendor : "No Vendor"}</div>; } } },
that seems as a work around but its also wrong cos serach cant work at the end of the day so more advancements need to be done i request that the development team copies how this works MaterialTable from "@material-table/core";
Thanks very much for creating this library. In my code, one of the columns receives an array of objects. I use customBodyRender to render the data as desired, problem is neither filtering nor searching works on this column because it parses the data as [Object object]. I tried converting the object property I want to display into an array of strings and I can't still filter nor search that column. I tried this example and the app crashes with the error "Objects can't be React children...".
Expected Behavior
Whether I pass an object or an array of strings, I should be able to filter and search that column.
Current Behavior
Dropdown filter only shows [Object object] or blank.
Steps to Reproduce (for bugs)
My data structure looks like this:
The code for the column is:
Your Environment