You can do something like this by displaying 1k
or 1m
accordingly if value it out of range.
const formatTotalCount = (params) => {
const totalCount = params.value;
if (totalCount >= 1000000) {
return `${(totalCount / 1000000).toFixed(1)}M+`;
} else if (totalCount >= 1000) {
return `${(totalCount / 1000).toFixed(1)}K+`;
} else {
return totalCount.toString();
}
};
const columns = [
{ field: 'totalCount', headerName: 'Total Count', width: 150, renderCell: formatTotalCount },
];
const rows = [
// Your data rows here
];
const MyDataGrid = () => {
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid rows={rows} columns={columns} pageSize={5} />
</div>
);
};
export default MyDataGrid;