groups data in a collection that has a plain tree-like structure according to the specified order and additional configuration
important
Data grouping isn't intended for working with lazyDataProxy
note
Grouped data can be serialized. After serialization data is available for rendering and editing as a plain tree-like structure
Usageâtype TGroupOrderFunc = (item: IDataItem) => string;
type TAggregate = "sum" | "count" | "min" | "max" | "avg" | string;
interface IGroupOrder {
by: string | TGroupOrderFunc;
map?: {
[field: string]: [string, TAggregate] | ((item: IDataItem[]) => string | number)
};
summary?: "top" | "bottom";
}
type TGroupOrder = string | TGroupOrderFunc | IGroupOrder;
interface IGroupConfig {
showMissed?: boolean | string;
field?: string;
}
group(order: TGroupOrder[], config?: IGroupConfig): void;
Parametersâ
order
- an array that defines the order and configuration for data grouping. Each element in the array can be:
(i: IDataItem) => string
for dynamic defining of a groupIGroupOrder
object that has the following properties:
by
- the field name or a function for user-defined groupingmap
- (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:
[string, TAggregate]
that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from the dhx.methods
helper(i: IDataItem[]) => string | number
summary
- (optional) specifies where the total row is rendered - at the top
or at the bottom
of the groupconfig
- (optional) the configuration of data grouping
showMissed
- (optional) specifies whether the elements that don't have the field for grouping should be displayed, true by default
field
- (optional) the group field name, "group" by defaultconst grid = new dhx.Grid("grid_container", {
columns: [
{ id: "salary", header: [{ text: "Salary" }] },
{ id: "experience", header: [{ text: "Experience (years)" }] },
{ id: "city", header: [{ text: "City" }] }
],
group: true,
groupable: true,
data: dataset
});
grid.data.group([
function(row) {
if (row.salary < 30000) return "Low income";
if (row.salary >= 30000 && row.salary < 70000) return "Medium income";
return "High income";
},
"city"
]);
const grid = new dhx.Grid("grid_container", {
columns: [
{ id: "department", header: [{ text: "Department" }] },
{ id: "employees", header: [{ text: "Number of Employees" }] },
{ id: "location", header: [{ text: "Location" }] }
],
group: true,
groupable: true,
data: dataset
});
grid.data.group([{
by: "department",
map: {
employees: ["employees", "sum"],
location: (rows) => {
const uniqueLocations = [...new Set(rows.map(r => r.location))];
return uniqueLocations.join(", ");
}
},
summary: "top"
}]);
showMissed
propertyconst grid = new dhx.Grid("grid_container", {
columns: [
{ id: "name", header: [{ text: "Name" }] },
{ id: "age", header: [{ text: "Age" }] },
{ id: "city", header: [{ text: "City" }] }
],
group: true,
groupable: true,
data: dataset
});
grid.data.group(["city"], {
showMissed: "Unknown City"
});
Change log:
added in v9.0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4