Want to sort with array object value
Expected Behavior
So i want to sort name , but there is a link function in it
Current Behavior
This my code for table options
const data = projects.map(p =>[
'${p.id}','${p.status}',['${p.id}','${p.name}'],'${p.type}','${p.createdBy}','${p.createdAt}','${p.live}'
])
there's an array object in it = ['${p.id}','${p.name}']
and this is my code for column name
{
name: "name",
id:"name",
label: "Name",
options: {
filter: false,
customBodyRender: (value) => {
return ( <Link to ="" onClick = {e => this.setID(e, value[0])}> {value[1]} </Link>
);
},
},
}
so value[0] is ${p.id} and value[1] is ${p.name}
i think column name can't sort because there's two value in it
take a look at my filters for column name
both id and name appear in it
| Tech | Version |
|---|---|
| Material-UI | ^3.9.3 |
| MUI-datatables | ^2.0.0 |
| React | ^16.8.6 |
| browser | |
| etc |
Have a look at the customSort option, as this might allow you to handle your array data.
I try it and this is my codesandbox i think the sort still not working https://codesandbox.io/embed/angry-wave-22pjc?fontsize=14
You have to modify the function so that when it gets your array data, it sorts it the way you want it to be sorted. Sorting single values and arrays together doesn't have any default meaning or order, so you have to supply the logic to tell it what you want it to do. Look into the js sort function for more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort.
customSort is what you want, but you've got to build out the logic that fits your use case.
thanks for your help, finally i found the solution this is my code sandbox maybe it can help the other with same issues https://codesandbox.io/embed/elegant-mclaren-l9buv?fontsize=14