The data grid component (ids-data-grid) is used to arrange tabular data in rows and columns for easier scanning and comparison. Data grids are very configurable in both design and functionality and they can be found within almost every product/app.
You should pass an array of objects in to the grid on the dataset object. Also pass the columns array which contains the column configuration. There are a number of events described in the events and API section, as well as the column settings.
A Read-Only data grid uses “Formatters” to render cell content. A number of these are listed in the API section and it is possible to create your own.
Use Cases
The data grid component is most useful when it is used for categorically sorting dense and repetitive information. Each individual item is listed down the Y axis of the chart, and their shared attribute categories are listed along the X axis. The resulting cells are filled with information that is relevant to the corresponding item and attribute.
Terminology
Title: The name of the data grid optionally appearing above the grid and describing the contents.
Options: An optionally actions menu button with functionality that operates on the entire data grid.
Cell: Body elements of the data grid that contain an object’s value or attribute. Cells should only contain one type of content or it can be confusing and hurt accessibility.
Header Cell: These cells contain the names of the columns in the grid and related functions like filtering and sorting. All cells below the header cell will hold values related to the attribute in the header cell.
Column: Cells stacked vertically that contain values relate to the attribute found on the top header cell.
Row: Each row contains one cell per column in the data grid, and each cell displays a single value in the bound data item.
Tree: Denotes the use of hierarchical data, with an expandable and collapsible hierarchy.
Themeable Parts
table allows you to further style the table main element
container allows you to further style the container element
body allows you to further style the body element
header allows you to further style the header element
headerCell allows you to further style the header cells
row allows you to further style the rows
cell allows you to further style the row cells
cell-selected allows you to further style row cells that are selected (in mixed-selection mode, activated cells are also styled)
tooltip-popup allows you to further style or adjust the outer tooltip popup element
tooltip-arrow allows you to adjust the tooltip arrow element
Features (With Code Examples)
A data grid is created by adding an ids-data-grid html element in the page and setting the options either inline in the markup or in the JS part of the code. You can only use simple types (string, boolean ect) for inline markup so passing the data and column arrangement is always done in the JS part. The data will be an array of objects so its in the correct tabular form. The columns are also an array of objects but with defined options and types. See more about columns in next section.
Setting column groups allows you to add a second level of columns in your header and the ability to group the first level. This is useful for when you have a large number of columns and you want to group them into logical or related sections.
Column groups are achieved by providing an array to the columnGroups setting. Only one level of column groups can be defined.
If the column is hidden it will be automatically removed from the colspan. If in the last group you didn’t provided a bug enough colspan it will be set to the remaining columns. The name text can be right or left aligned and given an id. The only required property is colspan.
Disabling Rows
Disabling rows with certain conditions can be done by using the isRowDisabled setting. isRowDisabled is a callback function that takes in rowNumber and rowData as parameters. This can be used to make conditional checks for rows.
Here is an example on using isRowDisabled. This will disable rows that have row data with the activity variable equal to “Assemble Paint”.
Disabling the sorting in datagrid can be done using disableClientSort setting or the disable-client-sort attribute. This will disable the default sorting in the component but still update the sorting icon status on the button.
The data grid selection feature involves the setting rowSelection. This can be one of several values.
false No selection enabled.
multiple Allows multiple rows to be selected. When doing this it is recommended to add a formatters.selectionCheckbox for the first column.
single Allows a single row to be selected. When doing this you can optionally to add a formatters.selectionRadio for the first column. You can use the suppressRowDeselection if you want one row to always be selected.
mixed Allows multiple rows to be selected by clicking only on the checkbox or Space key. If clicking a row then that row is activated, meaning it is the current row and something might be shown based on the data of that row. You can use the suppressRowDeactivation if you want one row to always be selected.
The following events are relevant to selection/activation.
rowselected Fires when an individual row is activation and gives information about that row.
rowdeselected Fires when an individual row is deselected and gives information about that row.
selectionchanged Fires once for each time selection changes and gives information about all selected rows.
rowactivated Fires when an individual row is activated and gives information about that row.
rowdeactivated Fires when an individual row is deactivated and gives information about that row.
activationchanged Fires once for each time activation changes and gives information about the active row.
The following settings are relevant to ui state of header checkbox
disableHeaderCheckbox When true, disable the ui interaction of header checkbox but the data row checkboxes are still enabled.
hideHeaderCheckbox When true, hides the ui of header checkbox but the data row checkboxes are still visible.
Tree Grid
The tree grid feature involves the setting treeGrid to true. In addition the data passed to the tree grid should contain a field called children. That contains the child rows. This can by unlimited levels but 2-4 is recommended as a max for a more usable UI. In addition you can preset some states by adding rowExpanded: false to the parent elements (default is expanded). And also set rowHidden: false for child rows that are expanded. You also need a Expander formatter on a cell (usually the first visible cell.
The following events are relevant to selection/activation.
rowexpanded Fires when a tree grid row is expanded by click or keyboard.
rowcollapsed Fires when a tree grid row is collapsed by click or keyboard.
Some additional settings are needed or possibly needed.
idColumn {string} For saving the row state during sort this should be set to the id column in the data set. Defaults to id.
groupSelectsChildren {boolean} If the tree grid has multiple selection, setting this will select all children when a parent is selected.
suppressRowClickSelection {boolean} If using selection you might want to set this so clicking a row will not select it.
Expandable Row
The Expandable Row feature involves the setting expandableRow to true. In addition a row template should be provided via an id that points to the expandableRowTemplate which is a template element. You can preset the expandable state by adding rowExpanded: true to the row element you want to expand. The default is collapsed.
Here is a code example for an expandable row
<ids-data-gridid="data-grid-expandable-row"expandable-row="true"expandable-row-template="expandable-row-tmpl"label="Books"><templateid="expandable-row-tmpl"><ids-layout-gridauto-fit="true"padding-x="md"><ids-textfont-size="16"type="span">${convention}</ids-text></ids-layout-grid><ids-layout-gridauto-fit="true"padding-x="md"><ids-textfont-size="14"type="span">${price} USD</ids-text></ids-layout-grid><ids-layout-gridauto-fit="true"padding-x="md"><ids-textfont-size="14"type="span">Lorem Ipsum is simply sample text of the printing and typesetting industry. Lorem Ipsum has been the industry standard sample text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only...</ids-text></ids-layout-grid></template></ids-data-grid>
The following events are relevant to expandable rows
rowexpanded Fires when a tree grid row is expanded by click or keyboard.
rowcollapsed Fires when a tree grid row is collapsed by click or keyboard.
Some additional settings are needed or possibly needed.
idColumn {string} For saving the row state during sort this should be set to the id column in the data set. Defaults to id.
expandableRowTemplate {string} Should point to the row template element.
Editing
The Editing features start by setting editable to true. In addition you should add editors to columns and enable features of each of the editors. The features differ depending on the component used for editing. See the Keyboard section for information on which keys can be used when editing..
To cancel or disabled editing there are a few ways:
setting the column editor setting to undefined will disable editing on the column (as will not having an editor setting at all).
adding a readonly or disabled function which returned true for some cells based on a condition will disable or mark the cell readonly.
return false in the beforecelledit event in the response function
The following settings are available on editors.
type As of now can be checkbox, input, datepicker, timepicker, dropdown, or tree but more will be added.
inline Default is false. If true the editor (for example an input) will be visible in a field.
editorSettings Is an object that is loosely typed that lets you pass any option the editor supports in. For example any of the IdsInput or IdsCheckbox options can be passing in. Some special ones are:
editorSettings.autoselect Text will be selected when entering edit mode. If false, cursor will be appended to end of input value.
editorSettings.dirtyTracker Enables the dirty tracker that marks changed cells.
editorSettings.browserAutocomplete Adds the autocomplete attribute to the editor input element allowing for browser autocomplete. This can be on, off (default), or name, email, street-address, postal-code, search, tel, url, username, off ect. This not to be confused with the autocomplete setting which will enable additional autocomplete component functionality (see autocomplete examples).
editorSettings.validate Text will be selected when entering edit mode
editorSettings.mask Will pass mask settings to the input (if supported).
editorSettings.maskOptions Will pass maskOptions settings to the input (if supported).
editorSettings.options Dataset used for dropdown editor’s list box options. If none are specified the value in the data will be applied as the only options.
editorSettings.maxlength Sets the input editor’s maxlength property to the max characters you can type
editorSettings.uppercase Sets the input editor’s to all uppercase
editorValidation Optional property to set custom validation rule
editorValidation.check Callback function for custom validation. It is passed the editable cell’s input field and expects a boolean value in return
editorValidation.message Error message displayed when the validation check fails
editorValidation.id Unique id for the validation rule
showEditorIcons Sets the editable cell icons to be always open or only on hover. Default is hover.
When the use clicks in the cell or activates editing with the keyboard with the Enter key and types. The following events will fire.
beforecelledit Fires before a cell is being edit (before edit is started). Can be vetoed by returning false as shown below.
celledit Fires exactly when a cell is being edited.
endcelledit Fires when a cell edit is completed and changed.
cancelcelledit Fires when an edit is cancelled via the Esc key.
To cancel editing based on some condition or if editing is not allowed you can veto the beforecelledit event.
There are a few utility functions for editing the data grid mentioned in the Methods section.
Grouped Rows (Groupable)
The grouped row feature start by setting groupable setting to an object containing fields to group by. Only one group by field is currently supported.
dataGrid.groupable = {
fields: ['type']
};
The groupable object can contain the following properties some are for future support. Aggregators do work in the data now but the footer is not yet available.
fields {array} Sets the field to group by on
aggregators {array} For future support.
expanded: {boolean | function} For future support.
groupRowFormatter: {function} For future support.
groupFooterRow: {boolean} For future support.
groupFooterRowFormatter: {function} For future support.
When a row is collapsed the internal grouped data will set a fieldgroupCollapsed on your data object and hide child rows.
Column Sizing
The columns can be sized by using the width, minWidth, and maxWidth settings. They have a few options that can be used to control the sizing in different ways. I.E. There are three column configurations: auto, fixed and percent.
Unspecified – The column will be sized by the content minmax(150px, 1fr) to a reasonable / readable default. This is known as auto columns.
150 { integer } – The column will be a fixed size in pixels if provided as an integer.
10% { string } – The column will be a percentage of the table width.
minmax(130px, 4fr) { string } – The column will be a minimum of 150px and a maximum of 1fr. This is useful for a stretch column. (see example columns-stretch.html)
10ch { string } – The column will be sized to 10 characters wide. This is an approximation based on the largest size character W in a default font plus a buffer so not exact for every character possible.
max-content { string } – The column will be sized to the max width of the content in the column. Either the title or the biggest cell content depending what is bigger. This method needs to scan the entire data set to determine the max width so is slightly slower. If virtual scrolling is enabled this will only scan the data that is in the visible buffer.
For a spacer column you just need to specify one extra column at the end (see example columns-fixed.html).
Settings and Attributes
When used as an attribute in the DOM the settings are kebab case, when used in JS they are camel case.
id-column {string} This setting will specify the name of the field which acts as the primary key for the data in the table. Some actions like saving row states across pages require this field to save the data back into the data set properly. Defaults to id.
virtualScroll {boolean} When virtual scroll is used the grid can render many thousands of rows and only the rows visible in the scroll area are rendered for performance. This setting has limitations such as the rows need to be fixed size.
addNewAtEnd {boolean} Automatically append rows while keyboard navigating data grid in edit mode.
allow-one-expanded-row {boolean} This setting will allow only one expandable-row to be opened/expanded at a time. Defaults to false.
alternateRowShading {boolean} For better scan-ability you can shade alternate rows.
listStyle {boolean} Sets the style of the grid to list style for simple readonly lists.