UNPKG

@anglr/grid

Version:
89 lines 2.87 kB
import { isBlank, isString } from '@jscrpt/common'; import { GridPluginType } from './enums'; /** * Applies block of row selection to grid, if row was not selected checkbox change event will be blocked * @param grid - Instance of grid which is used * @param itm - Data item for row * @param event - Mouse event that occured */ export function applyRowSelectionBlock(grid, itm, event) { const rowSelector = grid.getPlugin(GridPluginType.RowSelector); if (!rowSelector.isSelected(itm) && event.target.checked) { event.preventDefault(); } } /** * Serialize ordering * @param ordering - Ordering to be serialized */ export function serializeSimpleOrdering(ordering) { if (!ordering) { return null; } return encodeURIComponent(`${ordering.orderBy},${ordering.orderByDirection}`); } /** * Deserialize ordering * @param ordering - Ordering as string to be deserialized */ export function deserializeSimpleOrdering(ordering) { if (!ordering) { return null; } const [orderBy, orderByDirection] = decodeURIComponent(ordering).split(','); return { orderBy: orderBy, orderByDirection: +orderByDirection }; } /** * Creates context object for cell in grid * @param grid - Instance of grid * @param plugins - Instances of all plugins * @param index - Index of current row in header * @param columnMetadata - Metadata for column */ export const cellContextFactory = function cellContextFactory(_grid, _plugins, _index, columnMetadata) { return { column: columnMetadata, }; }; /** * Creates context object for data cell in grid * @param grid - Instance of grid * @param plugins - Instances of all plugins * @param data - Data for row that is being rendered * @param index - Index of current row in header * @param columnMetadata - Metadata for column */ export const dataCellContextFactory = function dataCellContextFactory(_grid, plugins, data, index, columnMetadata) { const paging = plugins[GridPluginType.Paging]; const rowSelector = plugins[GridPluginType.RowSelector]; return { $implicit: data, column: columnMetadata, index: index, rowIndex: paging.firstItemIndex + index, startingIndex: paging.firstItemIndex, get isSelected() { return rowSelector.isSelected(data); }, }; }; /** * Transforms row columns attribute value into row columns value * @param value - Value to be transformed as row columns attribute */ export function rowColumnsAttribute(value) { if (isBlank(value)) { return value; } if (value === '') { return []; } if (isString(value)) { throw new Error(`rowColumnsAttribute: invalid value ${value}, must be array or empty string or null or undefined!`); } return value; } //# sourceMappingURL=utils.js.map