I am trying to sort data with nested values in a Data Grid But getting undefined on sortComparator of Data Grid Columns
Code: Column Data Setup:
{
headerName: 'Title',
field: `${this.props.type}.title`,
width: 500,
type: "string",
renderCell: (valueReceived) => this.getImageorVideoLogo(valueReceived.row),
sortComparator: this.titleSorting
}
titleSorting = (a,b)=>{
console.log(a);
console.log(b);
}
Data Grid:
<DataGrid
rows={rowsDataGrid}
columns={columnsDataGrid}
ponents={{
Toolbar: this.getSearchTextField
}}
pageSize={5}
rowsPerPageOptions={[5]}
// checkboxSelection
// disableSelectionOnClick
autoHeight
/>
Problem both console print undefined Ideally it should give either the whole row a and row b or atleast row a column data and row b column data
I am trying to sort data with nested values in a Data Grid But getting undefined on sortComparator of Data Grid Columns
Code: Column Data Setup:
{
headerName: 'Title',
field: `${this.props.type}.title`,
width: 500,
type: "string",
renderCell: (valueReceived) => this.getImageorVideoLogo(valueReceived.row),
sortComparator: this.titleSorting
}
titleSorting = (a,b)=>{
console.log(a);
console.log(b);
}
Data Grid:
<DataGrid
rows={rowsDataGrid}
columns={columnsDataGrid}
ponents={{
Toolbar: this.getSearchTextField
}}
pageSize={5}
rowsPerPageOptions={[5]}
// checkboxSelection
// disableSelectionOnClick
autoHeight
/>
Problem both console print undefined Ideally it should give either the whole row a and row b or atleast row a column data and row b column data
Share Improve this question edited Mar 27 at 7:25 Olivier Tassinari 8,6916 gold badges25 silver badges28 bronze badges asked May 18, 2022 at 5:53 ash1102ash1102 4571 gold badge5 silver badges22 bronze badges1 Answer
Reset to default 6Try with a custom field and the valueGetter param :
{
headerName: 'Title',
field: "CustomField",
valueGetter: () => this.props.type.title,
width: 500,
type: "string",
renderCell: (valueReceived) => this.getImageorVideoLogo(valueReceived.row),
sortComparator: this.titleSorting
}
And add a parison algorithm in your parator function such as
const titleSorting = (a, b) => {
a - b;
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744083533a4555745.html
评论列表(0条)