UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

80 lines (79 loc) 2.6 kB
export const STYLED_COLUMN_ROW_KINDS = ['Data', 'Group', 'Summary', 'Total']; export const STYLED_COLUMN_ROW_KIND_EXCLUDE_KEY = { Data: 'ExcludeDataRows', Group: 'ExcludeGroupRows', Summary: 'ExcludeSummaryRows', Total: 'ExcludeTotalRows', }; export const isStyledColumnRowKindSupported = (styledColumn, kind) => { if (styledColumn.SparklineStyle) { return kind === 'Data'; } return true; }; export const getStyledColumnRowKindDisabledReason = (styledColumn, kind) => { if (isStyledColumnRowKindSupported(styledColumn, kind)) { return undefined; } if (styledColumn.SparklineStyle) { return 'Sparklines only apply to leaf data rows (cells with a numeric array of points).'; } return undefined; }; export const getStyledColumnRowKindForNode = (node, api) => { if (api.gridApi.isGrandTotalRowNode(node)) { return 'Total'; } if (api.gridApi.isSummaryNode(node)) { return 'Summary'; } if (api.gridApi.isGroupRowNode(node)) { return 'Group'; } return 'Data'; }; export const sanitizeStyledColumnRowScope = (styledColumn) => { const scope = styledColumn.RowScope; if (!scope) { return undefined; } let next = { ...scope }; let changed = false; for (const kind of STYLED_COLUMN_ROW_KINDS) { if (isStyledColumnRowKindSupported(styledColumn, kind)) { continue; } const key = STYLED_COLUMN_ROW_KIND_EXCLUDE_KEY[kind]; if (next[key] !== true) { next = { ...next, [key]: true }; changed = true; } } return changed ? next : undefined; }; export const shouldRenderStyledColumnOnRow = (styledColumn, node, api) => { const rowKind = getStyledColumnRowKindForNode(node, api); if (!isStyledColumnRowKindSupported(styledColumn, rowKind)) { return false; } const isGroup = api.gridApi.isGroupRowNode(node); const isTotal = api.gridApi.isGrandTotalRowNode(node); const isSummary = !isTotal && api.gridApi.isSummaryNode(node); const isLeaf = !isGroup && !isSummary && !isTotal; const scope = styledColumn.RowScope; if (scope) { if (isLeaf && scope.ExcludeDataRows) return false; if (isGroup && scope.ExcludeGroupRows) return false; if (isSummary && scope.ExcludeSummaryRows) return false; if (isTotal && scope.ExcludeTotalRows) return false; return true; } if (styledColumn.BadgeStyle) { return true; } return !isGroup; };