Skip to content

[Bug] AdvancedDataGrid column sort does not handle null/undefined cell values — crashes on sort #632

Description

@RUKAYAT-CODER

Overview

src/components/common/AdvancedDataGrid.tsx sort comparator does direct string/number comparison on cell values. When a row has null or undefined for a sorted column (missing data, optional fields), the comparator crashes with Cannot read properties of null (reading 'toLowerCase') or returns NaN from undefined - undefined, corrupting the sort order silently.

Specifications

Features:

  • Sort comparator handles null, undefined, and empty string as 'less than' all valid values
  • Null/undefined rows sorted to end by default, configurable via nullsFirst?: boolean prop
  • String sort is case-insensitive and diacritic-normalized
  • No crash or warning for any null/undefined cell value

Tasks:

  • Add null guards in sort comparator: if (a == null && b == null) return 0; if (a == null) return 1; if (b == null) return -1;
  • Apply normalize + toLowerCase for string comparison
  • Add nullsFirst prop to column definition type
  • Add unit tests: sort with all-null column, mixed null/value column, and fully populated column

Impacted Files:

  • src/components/common/AdvancedDataGrid.tsx

Acceptance Criteria

  • Sort on a column with null values does not throw
  • Null values sort to end by default
  • nullsFirst={true} column prop reverses null position
  • Unit tests pass for null-only, mixed, and value-only sort scenarios

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions