group
Optional. Enables grouping row data by column values and allows configuring grouping settings
pro version only
The described functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.
info
Note that when you initialize Grid with the group configuration property, the tree-like mode is enabled for Grid and it will have the type: tree property in its configuration.
Usage
type TAggregate = "sum" | "count" | "min" | "max" | "avg" | string;
interface IGroupOrder {
by: string | ((row: IRow) => string);
map?: { [field: string]: [string, TAggregate] | ((row: IRow[]) => string | number) };
summary?: "top" | "bottom";
}
type IGroupOrderItem = string | IGroupOrder | ((row: IRow) => string);
interface IGroup {
panel?: boolean; // true by default
panelHeight: number; // 40 by default
hideableColumns?: boolean; // true by default
showMissed?: boolean | string; // true by default
showEmptyGroups?: boolean; // false by default
counter?: boolean | ((row: IRow) => string); // true by default
fields?: { [colId: string]: IGroupOrder };
order?: IGroupOrderItem[];
column?: string | ICol;
}
interface IGridConfig {
...
group?: boolean | IGroup;
...
}
Parameters
As an object the group configuration option has the following properties:
tip
You can find the detailed description of the group object properties with examples in the related guide Grouping data.
panel- (optional) enables the group panel, true by default. When thepanelconfig is set to true, a user can drag columns' headers to the panel of creating and modifying groupspanelHeight- (optional) defines the height of the group panel in pixels, which allows adjusting the space for rendering a group of columns, 40 by defaulthideableColumns- (optional) specifies whether columns will be hidden on a group creation, true by default. If set to false, columns used for grouping will remain visibleshowMissed- (optional) controls visibility of the elements that don't suit the grouping criteria (e.g. data without values), true by default- if set to true, the rows that don't have values for grouping are rendered row by row after all the data
- if a string value is set, e.g. "Missed", the rows that don't have values for grouping are rendered as a separate group the name of which will have the specified string value. This group will be rendered as the last one
- if set to false, the rows that don't suit the grouping criteria won't be rendered
showEmptyGroups- (optional) specifies whether a group that loses all its rows stays in the grid, false by default- if set to false, such a group leaves the view together with its summary row and its nested groups.
resetFilter()brings back a group emptied by filtering, while a group emptied byremove()leaves the grid for good - if set to true, such a group remains visible with the
$count: 0value and emptied aggregates: the "sum" and "count" aggregations give 0, while "avg", "min" and "max" give null, as described in the Data calculation functions guide
- if set to false, such a group leaves the view together with its summary row and its nested groups.
counter- (optional) defines the text rendered next to the group name in the column with grouped data, true by default- if set to true, Grid renders the current number of rows of the group in brackets, e.g. (2)
- if set to false, Grid renders only the group name
- if set to a function, Grid calls it with the group header row, and the function returns the string to render. Grid inserts the returned value as HTML, so it may contain markup; an empty string renders no counter. The row gives access to the
$count,$totalCountand$byservice properties and to every aggregated field of themapobject of the level
fields- (optional) predefines an extended configuration for data grouping by certain columns, by setting the rules of aggregation and rendering of the results. The attributes of thefieldsobject correspond to the ids of columns for which the aggregation rules and the order of results are being configured. The configuration of a column is defined by theIGroupOrderobject that has the following properties:map- (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:- a tuple
[string, TAggregate]that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from thedhx.methodshelper - a user-defined aggregation function
((row: IRow[]) => string | number)
- a tuple
summary- (optional) specifies where the total row is rendered - at thetopor at thebottomof the group
order- (optional) defines the order of grouping by setting the sequence of columns for grouping. The elements of theorderarray can be:- a string that represents a grouping field
- a function
((row: IRow) => string)for dynamic defining of a group - an
IGroupOrderobject that has the following properties:by- the field name or a function((row: IRow) => string)for user-defined groupingmap- (optional) an object for data aggregation in a group, where the keys are field names, and the values can be:- a tuple
[string, TAggregate]that specifies the field and the aggregation type ("sum", "count", "min", "max", "avg") from thedhx.methodshelper - a user-defined aggregation function
((row: IRow[]) => string | number)
- a tuple
summary- (optional) specifies where the total row is rendered - at thetopor at thebottomof the group
column- (optional) defines the configuration of a column that renders values of the grouped data. This column will be used as a main one for structuring and rendering data grouped by value
Example
const grid = new dhx.Grid("grid_container", {
columns: [
{ id: "country", header: [{ text: "Country" }], groupable: true },
{ id: "population", header: [{ text: "Population" }] },
{ id: "area", header: [{ text: "Land Area (Km²)" }] }
],
group: {
panel: true
},
data: dataset
});
Related article: Grouping data
Related sample: Grid. Group counter after filtering
Change log:
- The
counterandshowEmptyGroupsproperties are added in v9.4 - Added in v9.0