UNPKG

@progress/kendo-angular-chart-wizard

Version:

Kendo UI Angular Chart Wizard component

51 lines (50 loc) 2.29 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { getter } from "@progress/kendo-common"; import { isPresent } from "@progress/kendo-angular-common"; /** * Maps the Grid `selectedKeys` to a general `DataRows` type for the Chart Wizard. * * The `selectedKeys` can be row keys or cell keys. * * @returns Returns a `DataRow[]` that you can pass to `getWizardDataFromDataRows` to bind the Chart Wizard. */ export function getGridSelectedRows(args) { const { grid, data, selectedKeys, selectionKey, columnKey } = args; const columns = [...grid.leafColumns]; const allColumns = columns.map((column) => ({ field: column.field, title: column.title })); const selectedColumns = new Map(); let getItemByKey; if (selectionKey) { const idGetter = getter(selectionKey); const dataMap = new Map(data.map((item) => [idGetter(item), item])); getItemByKey = itemKey => dataMap.get(itemKey); } else { getItemByKey = itemIndex => data[itemIndex]; } let getColumnByColumnKey = key => columns[key]; if (typeof columnKey === "function") { const columnMap = new Map(columns.map((col, colIndex) => [columnKey(col, colIndex), col])); getColumnByColumnKey = key => columnMap.get(key); } selectedKeys.forEach(item => { if (isPresent(item.columnKey)) { const itemColumns = selectedColumns.get(item.itemKey) || []; const column = getColumnByColumnKey(item.columnKey); const columnIndex = columns.indexOf(column); const dataColumn = { field: column.field, title: column.title }; itemColumns.splice(columnIndex, 0, dataColumn); selectedColumns.set(item.itemKey, itemColumns); } else { selectedColumns.set(item, allColumns); } }); return [...selectedColumns.entries()].map(([itemKey, dataColumns]) => ({ dataItem: getItemByKey(itemKey), dataColumns })); }