Sencha Documentation

Super classes

Adds the ability for single level grouping to the grid. A GroupingStore must be used to enable grouping. Some grouping characteristics may also be configured at the Column level

Sample usage:

var grid = new Ext.grid.GridPanel({
    // A groupingStore is required for a GroupingView
    store: new Ext.data.GroupingStore({
        autoDestroy: true,
        reader: reader,
        data: xg.dummyData,
        sortInfo: {field: 'company', direction: 'ASC'},
        groupOnSort: true,
        remoteGroup: true,
        groupField: 'industry'
    }),
    colModel: new Ext.grid.ColumnModel({
        columns:[
            {id:'company',header: 'Company', width: 60, dataIndex: 'company'},
            // groupable, groupName, groupRender are also configurable at column level
            {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price', groupable: false},
            {header: 'Change', dataIndex: 'change', renderer: Ext.util.Format.usMoney},
            {header: 'Industry', dataIndex: 'industry'},
            {header: 'Last Updated', renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
        ],
        defaults: {
            sortable: true,
            menuDisabled: false,
            width: 20
        }
    }),

    view: new Ext.grid.GroupingView({
        forceFit: true,
        // custom grouping text template to display the number of items per group
        groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
    }),

    frame:true,
    width: 700,
    height: 450,
    collapsible: true,
    animCollapse: false,
    title: 'Grouping Example',
    iconCls: 'icon-grid',
    renderTo: document.body
});

Config Options

 
The text to display when there is an empty group value (defaults to '(None)'). May also be specified per column, see ...
The text to display when there is an empty group value (defaults to '(None)'). May also be specified per column, see Ext.grid.Column.emptyGroupText.
 
enableGrouping : Boolean
false to disable grouping functionality (defaults to true)
false to disable grouping functionality (defaults to true)
 
true to enable the grouping control in the column menu (defaults to true)
true to enable the grouping control in the column menu (defaults to true)
 
enableNoGroups : Boolean
true to allow the user to turn off grouping (defaults to true)
true to allow the user to turn off grouping (defaults to true)
 
enableRowBody : Boolean
True to add a second TR element per row that can be used to provide a row body that spans beneath the data row. Use ...
True to add a second TR element per row that can be used to provide a row body that spans beneath the data row. Use the getRowClass method's rowParams config to customize the row body.
 
groupByText : String
Text displayed in the grid header menu for grouping by a column (defaults to 'Group By This Field').
Text displayed in the grid header menu for grouping by a column (defaults to 'Group By This Field').
 
groupMode : String
Indicates how to construct the group identifier. 'value' constructs the id using raw value, 'display' constructs the ...
Indicates how to construct the group identifier. 'value' constructs the id using raw value, 'display' constructs the id using the rendered value. Defaults to 'value'.
 
groupRenderer : Function
This property must be configured in the Ext.grid.Column for each column.
This property must be configured in the Ext.grid.Column for each column.
 
groupTextTpl : String
The template used to render the group header (defaults to '{text}'). This is used to format an object which contains ...
The template used to render the group header (defaults to '{text}'). This is used to format an object which contains the following properties:
  • group : String

    The rendered value of the group field. By default this is the unchanged value of the group field. If a groupRenderer is specified, it is the result of a call to that function.

  • gvalue : Object

    The raw value of the group field.

  • text : String

    The configured header (as described in showGroupName) if showGroupName is true) plus the rendered group field value.

  • groupId : String

    A unique, generated ID which is applied to the View Element which contains the group.

  • startRow : Number

    The row index of the Record which caused group change.

  • rs : Array

    Contains a single element: The Record providing the data for the row which caused group change.

  • cls : String

    The generated class name string to apply to the group header Element.

  • style : String

    The inline style rules to apply to the group header Element.

See Ext.XTemplate for information on how to format data using a template. Possible usage:
var grid = new Ext.grid.GridPanel({
    ...
    view: new Ext.grid.GroupingView({
        groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
    }),
});
 
true to hide the column that is currently grouped (defaults to false)
true to hide the column that is currently grouped (defaults to false)
 
ignoreAdd : Boolean
true to skip refreshing the view when new rows are added (defaults to false)
true to skip refreshing the view when new rows are added (defaults to false)
 
The selector used to find row bodies internally (defaults to 'div.x-grid3-row')
The selector used to find row bodies internally (defaults to 'div.x-grid3-row')
 
showGroupName : Boolean
If true will display a prefix plus a ': ' before the group field value in the group header line. The prefix will con...
If true will display a prefix plus a ': ' before the group field value in the group header line. The prefix will consist of the groupName (or the configured header if not provided) configured in the Ext.grid.Column for each set of grouped rows (defaults to true).
 
Text displayed in the grid header for enabling/disabling grouping (defaults to 'Show in Groups').
Text displayed in the grid header for enabling/disabling grouping (defaults to 'Show in Groups').
 
startCollapsed : Boolean
true to start all groups collapsed (defaults to false)
true to start all groups collapsed (defaults to false)

Properties

 
bodyTpl : Ext.Template
The template to use when rendering the body. Has a default template
The template to use when rendering the body. Has a default template
 
cellTpl : Ext.Template
The template to use to render each cell. Has a default template
The template to use to render each cell. Has a default template

Methods

 
Collapses all grouped rows.
Collapses all grouped rows.
 
Expands all grouped rows.
Expands all grouped rows.
 
findRowBody( HTMLElement el ) : HTMLElement
Return the HtmlElement representing the grid row body which contains the passed element.
Return the HtmlElement representing the grid row body which contains the passed element.

Parameters

  • el : HTMLElement
    The target HTMLElement

Returns

  • HTMLElement   The row body element, or null if the target element is not within a row body of this GridView.
 
getGroupId( String value ) : String
Dynamically tries to determine the groupId of a specific value
Dynamically tries to determine the groupId of a specific value

Parameters

  • value : String

Returns

  • String   The group id
 
getRowClass( Record record, Number index, Object rowParams, Store store ) : String
Override this function to apply custom CSS classes to rows during rendering. You can also supply custom parameters t...
Override this function to apply custom CSS classes to rows during rendering. You can also supply custom parameters to the row template for the current row to customize how it is rendered using the rowParams parameter. This function should return the CSS class name (or empty string '' for none) that will be added to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string (e.g., 'my-class another-class'). Example usage:
viewConfig: {
    forceFit: true,
    showPreview: true, // custom property
    enableRowBody: true, // required to create a second, full-width row to show expanded Record data
    getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
        if(this.showPreview){
            rp.body = '<p>'+record.data.excerpt+'</p>';
            return 'x-grid3-row-expanded';
        }
        return 'x-grid3-row-collapsed';
    }
},

Parameters

  • record : Record
    The Ext.data.Record corresponding to the current row.
  • index : Number
    The row index.
  • rowParams : Object
    A config object that is passed to the row template during rendering that allows customization of various aspects of a grid row.

    If enableRowBody is configured true, then the following properties may be set by this function, and will be used to render a full-width expansion row below each grid row:

    • body : String
      An HTML fragment to be used as the expansion row's body content (defaults to '').
    • bodyStyle : String
      A CSS style specification that will be applied to the expansion row's <tr> element. (defaults to '').
    The following property will be passed in, and may be appended to:
    • tstyle : String
      A CSS style specification that willl be applied to the <table> element which encapsulates both the standard grid row, and any expansion row.
  • store : Store
    The Ext.data.Store this grid is bound to

Returns

  • String   a CSS class name to add to the row.
 
toggleAllGroups( [Boolean expanded] ) : Void
Toggles all groups if no value is passed, otherwise sets the expanded state of all groups to the value passed.
Toggles all groups if no value is passed, otherwise sets the expanded state of all groups to the value passed.

Parameters

  • expanded : Boolean
    (optional)

Returns

  • Void
 
toggleGroup( String groupId, [Boolean expanded] ) : Void
Toggles the specified group if no value is passed, otherwise sets the expanded state of the group to the value passed...
Toggles the specified group if no value is passed, otherwise sets the expanded state of the group to the value passed.

Parameters

  • groupId : String
    The groupId assigned to the group (see getGroupId)
  • expanded : Boolean
    (optional)

Returns

  • Void
 
toggleRowIndex( Number rowIndex, [Boolean expanded] ) : Void
Toggle the group that contains the specific row.
Toggle the group that contains the specific row.

Parameters

  • rowIndex : Number
    The row inside the group
  • expanded : Boolean
    (optional)

Returns

  • Void