Skip to content

Commit 32afca9

Browse files
amir-baNOMADE55
andauthored
fix(data-grid): prevents null or undefined break max content length calculation (#2395)
* fix(data-grid): prevents null or undefined break max content length calculation * fix(data-grid): add null check for column values during sorting --------- Co-authored-by: Lucas Terracino <lukas.nomade@gmail.com>
1 parent 9fbe1c6 commit 32afca9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/components/src/components/data-grid/data-grid.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export class DataGrid {
380380
let maxLength = 0;
381381
let longestContent;
382382
rows.forEach((row) => {
383-
const length = row[columnIndex].toString().length;
383+
const length = row[columnIndex]?.toString()?.length || 0;
384384
if (length > maxLength) {
385385
longestContent = row[columnIndex];
386386
maxLength = length;
@@ -470,14 +470,14 @@ export class DataGrid {
470470
case 'date':
471471
if (sortDirection === 'ascending') {
472472
this.rows.sort((a, b) => {
473-
const textA = a[columnIndex].toLowerCase();
474-
const textB = b[columnIndex].toLowerCase();
473+
const textA = a[columnIndex]?.toLowerCase();
474+
const textB = b[columnIndex]?.toLowerCase();
475475
return textA < textB ? -1 : textA > textB ? 1 : 0;
476476
});
477477
} else {
478478
this.rows.sort((a, b) => {
479-
const textA = a[columnIndex].toLowerCase();
480-
const textB = b[columnIndex].toLowerCase();
479+
const textA = a[columnIndex]?.toLowerCase();
480+
const textB = b[columnIndex]?.toLowerCase();
481481
return textA > textB ? -1 : textA < textB ? 1 : 0;
482482
});
483483
}

0 commit comments

Comments
 (0)