UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

51 lines (50 loc) 1.58 kB
export function sortModelToSortItems(items, lookup) { return items .map((c) => { const columnId = c.columnId; const sortDirection = c.isDescending ? "descending" : "ascending"; if (c.sort.kind === "custom") { return { isCustom: true, sortDirection, columnId: c.columnId ?? undefined, originalSort: c, }; } const column = lookup.get(columnId); if (!column) return; let value = "values"; if (c.sort.kind === "string") { const opts = c.sort.options; if (opts?.nullsFirst) value += "_nulls_first"; if (opts?.caseInsensitive) value += "_insensitive"; if (opts?.ignorePunctuation) value += "_ignore"; if (opts?.trimWhitespace) value += "_trim"; } if (c.sort.kind === "number") { const opts = c.sort.options; if (opts?.nullsFirst) value += "_nulls_first"; if (opts?.absoluteValue) value += "_absolute"; } if (c.sort.kind === "date") { const opts = c.sort.options; if (opts?.nullsFirst) value += "_nulls_first"; } return { isCustom: false, columnId, sortDirection, label: column?.name ?? column?.id, sortOn: value, }; }) .filter((c) => c != null); }