igniteui-webcomponents
Version:
Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.
34 lines • 1.13 kB
JavaScript
import { groupBy } from '../../common/util.js';
export default class GroupDataOperation {
constructor() {
this.orderBy = new Map(Object.entries({
asc: 1,
desc: -1,
}));
}
apply(data, controller) {
const { groupingOptions: { groupKey, valueKey, displayKey, direction }, } = controller;
if (!groupKey)
return data;
const groups = Object.entries(groupBy(data, (item) => item.value[groupKey] ?? 'Other'));
if (direction !== 'none') {
const orderBy = this.orderBy.get(direction);
groups.sort((a, b) => {
return orderBy * controller.compareCollator.compare(a[0], b[0]);
});
}
return groups.flatMap(([group, items]) => {
items.unshift({
dataIndex: -1,
header: true,
value: {
[valueKey]: group,
[displayKey]: group,
[groupKey]: group,
},
});
return items;
});
}
}
//# sourceMappingURL=group.js.map