admin管理员组文章数量:1393858
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;
}
版权声明:本文标题:javascript - Sorting not working for MUI X Data Grid: Data Grid sortComparator giving undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744083533a2588092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论