Grid Attributes
Grid Configuration
Grid configurations are passed as the third argument to the FusionGrid constructor while instantiating it. It contains an object with several properties to configure, like columns, rows, inline charts, etc. Here is the syntax:
var grid = new FusionGrid(container, dataTable, gridConfig);
Let’s explore all possible configurable properties available in the grid configuration.
Columns and Headers
Using this property you can configure columns in the grid. It accepts an array of objects. Here is the syntax:
var gridConfig = {
columns: [
{
key_1: 'value_1,
key2_2: 'value_2',
},
]}
Selecting columns
By default, all data table columns are rendered in the grid. The user can customize this behavior as follows:
config = {
columns: [{
field: 'country_name'
}, {
field: 'continent'
}]
};
Here the field is the column name mentioned in the data table schema.
Changing Column Header name
The header text is the same as the corresponding schema field name for a column bound with a schema field. The user can provide the header name explicitly as follows:
config = {
columns: [{
field: 'country_name',
headerText: 'Country'
}, {
field: 'continent',
headerText: 'Continent',
}]
};
A blank or empty string is also a valid header text if the user wants to render a column without any header name.
Changing Column Appearances
The user can change the appearance of all the cells of a column, including the header cells, as follows:
config = {
columns: [{
field: 'country_name',
class: 'a-css-class'
}, {
field: 'continent',
class: 'another-css-class'
}]
};
Or change the appearance of just header cell like this:
config = {
columns: [{
field: 'country_name',
headerClass: 'a-css-class-name'
}, {
field: 'continent',
headerClass: 'another-css-class-name'
}]
};
Or change the appearance of value cells like this:
config = {
columns: [{
field: 'country_name',
cellClass: 'a-css-class-name'
}, {
field: 'continent',
cellClass: 'another-css-class-name'
}]
};
We recommend using class only to style the grid.
Column Grouping
To create a multi-column group, the user needs to define group names and then columns as children of the group. Any column which has children is considered as a group. The Group header must not be linked to any field in the schema, if it’s specified, the field attribute will be ignored, and a warning is displayed.
config = {
columns: [{
headerName: 'Employee Details',
children: [{
field: 'Name'
},{
field: 'Country'
}]
}]
};
Configuring Column Hover
By default, column hover is not enabled, but the user can enable the setting and also define hover style as follows:
config: {
columns: [{
field: 'Address',
width: '300px',
hover: {
enable: true,
class: 'css-class-name'
}
}]
}
Column Type and Format
Before going into the details of column type, there’s an important attribute called formatter.
Formatter
is a callback function that executes before rendering each cell, as follows:
formatter: function(params) {}
Here params
contain three major properties -
cellValue
- contains the current cell valuevalues
- values of all cells of the current recordcellIndex
- index of the cell
There are a total of 4 column types available in the grid; string
, number
, datetime
, and html.
String Column Type
The most common type, and you can use it as follows:
config = {
columns: [{
field: 'country_name',
type: 'string'
}]
};
Number Column Type
Add numbers like this:
config = {
columns: [{
field: 'Revenue',
type: 'number'
}]
};
And add numbers using formatters, like this:
config = {
columns: [{
field: 'Revenue',
formatter: function(params) {
return '$' + parseFloat(params.cellValue).toFixed(2);
}
}]
}
In this example, the decimal number is fixed to 2 values, always
and also
, to denote the currency $
is added before the value.
Datetime Column Type
Here is how to use the Datetime
style for your columns:
config = {
columns: [{
field: 'registration_date',
headerText: 'Registration Date & Time',
type: 'datetime'
}]
};
HTML Column Type
When custom HTML cells are needed.
config = {
columns: [{
headerText: 'Player Name',
type: 'html',
template: function(params) {
return (
'<span class='player-name'><img src=' + params.values['playerPicURL'] + '/>' + params.values['playerName'] + '</span>'
);
}
}]
};
Here is a list of properties supported in columns:
Property Name | Data Type | Description |
---|---|---|
field |
String | Name of the schema field. It should be mapped to a valid property name in FusionDataStore schema. For example: { field: 'Assembly Location' } |
type |
String | Data type of the column. It accepts following values in string format: string , number , datetime , and html . If this value is not provided, then by default it will take it from the FusionDataStore schema. |
headerText |
String | Name of the column which will appear in the grid. By default it will be the same as field. For example: { headerText: 'Assembly Location in US' }. |
class |
Array, Function | An array of class names in string format which is assigned to the entire column including cells and headers. It is useful to customize the appearance of the column. For example: : { class: ['class-1', 'class-2'] } Or you could assign a function which should return an array of class names. This function provides a parameter which provides following properties: 1. cellValue: Value of the cell 2. cellIndex: Index of the cell 3. rowIndex: Index of the row 4. values: An object of values for the given rows Here is an example of setting up the function: : { class: function(params) { } } |
headerClass |
Object, Function | Works exactly like class but the class name will get applied to the column header only. |
cellClass |
Object, Function | Works exactly like class but the class name will get applied to the cells only. |
cellStyle |
Object, Function | Works exactly like style but the class name will get applied to the cells only. |
enableHover |
boolean | Enables hover state for the column. |
hoverClass |
Object, Function | Works exactly like class but the class name will get applied when you hover the cell only. |
template |
Fuction | If type is set to html, then you have to return an HTML string that gets applied to the entire cell. Function provides a parameter which will allow you to read corresponding cell and row values. For example: { template: function (params) {} }. |
formatter |
Object, Function | If you want to add some inline styles, conditional or number formatting on the data, then this function is handy. { formatter: function (params) {} }. |
tooltip |
Object | Allows you to configure tooltips appearing on the cell or column. |
Layout Configurations
Allows you to define layout-related properties for the grid. It accepts only objects. Choose between these four layout configurations for your grid; type, density, template, and autoHeight.
var gridConfig = {
layout : { key_1: 'value_1' }
}
Layout Type
Choose your layout type by selecting between row
or card
.
config = {
layout: {
type: 'row'/'card'
}
}
Layout Density
There are three options available to control the density of rows in a grid; default, compact, and comfortable.
config = {
layout: {
type: 'row',
density: 'default'/'compact'/'comfortable'
}
}
Automatic Height
Users can choose to enable the autoHeight
attribute. If the volume of data is high, then vertical scrollbars appear and if the volume of data is low, then the rest of the space is left blank. To override this behavior, i.e. expand or shrink grid size based on its content, users can choose to enable the flag autoHeight. For example:
config = {
layout: {
autoHeight: true
}
}
Number of cards in a row
Use this attribute to configure the number of cards you wish to place in a row. Every card will have the same width and if any text cannot be accommodated in the assigned width, then an ellipsis will appear. For example:
config = {
layout: {
numCards: 4
}
}
Here is a list of configurations available under layout:
Property Name | Data Type | Description |
---|---|---|
type |
String | A layout can be one of two types - row or card layout. By default the value is always row . |
density |
String | Controls the density of rows in a grid, there are two options available: compact, comfortable. This is applicable for row layouts only. |
autoHeight |
Boolean | By default, the grid is configured to render in the space it’s designated for. |
numCards |
Number | Users can configure the number of cards to place in a row. |
Pagination
This property allows you to configure the pagination component of the grid. Here is the syntax:
var gridConfig = {
pagination : { key_1: 'value_1' }
}
Simple Pagination
Use only two arrows to navigate between pages, like this:
config = {
pagination: {
enable: true
}
}
Show Page Numbers
To show the page number on top of the navigation arrows, follow this example:
config = {
pagination: {
showPages: {
enable: true
}
}
}
Show Total number of Pages
To show the current page number, the total number of pages as well as arrows, follow the example below:
config = {
pagination: {
showPages: {
showTotal: true
}
}
}
Jump to a specific page
Users can also enable jumping to a specific page, apart from linear navigation.
config = {
pagination: {
showPages: {
userInput: true
}
}
}
Show Total number of Rows
This attribute shows the total number of rows in the grid and the currently viewed rows.
config = {
pagination: {
showRecordCount: true
}
}
Configuring Page Size
Users can configure the default page size like this:
config = {
pagination: {
pageSize: {
default: 30
}
}
}
Or use the options
attribute and select page size from the dropdown options:
config = {
pagination: {
pageSize: {
options: true/false/[number array],
}
}
}
If a user provides an array of numbers, those numbers are shown in the dropdown options. If a user provides any value beyond the range of the total number of elements, we will show those values, but if someone chooses those values, we will show all elements. If all provided values are beyond the range, we will fall back to default options. If the default page size is not provided but options are configured, then the first value of the options array will be considered the default page size. Suppose both options and default page size are configured, but the default page size value is not present in the options array. In that case, the first value of the options array will be considered as default page size, and additionally, an error will be logged in the background.
First and Last pages
If this control is set to true, then two buttons will appear to navigate to the first or last page:
config = {
pagination: {
showJumpToEndButtons: true
}
}
Users can also individually disable the start or end button
config = {
pagination: {
showJumpToFirstPageButton: false,
showJumpToLastPageButton: true
}
}
Here is a list of the available options:
Property Name | Data Type | Description |
---|---|---|
enable |
Boolean | Enables pagination in the grid. |
showPages |
Object | Enables you to configure page count. It has following properties available: enable: Enables page numbers in the pagination. showTotal: Show total number of pages available. userInput: Allows users to input page number. |
showRecordCount |
Boolean | Shows the total number of rows in the grid. For example: { showRecordCount : true } |
pageSize |
Object | Allows you to configure page size-related controls. It offers the following properties: 1. default: Default page size. It should be numerical. 2. options: It accepts both boolean and an array of numbers to show the dropdown for users to configure page size. |
showJumpToEndButtons |
Boolean | If this property is set to true, then both jump-to-first and jump-to-last buttons will appear for navigation. |
showJumpToFirstPageButton |
Boolean | If this property is set to true, then only the jump-to-first button will appear for navigation. |
showJumpToLastPageButton |
Boolean | If this property is set to true, then only the jump to-last button will appear for navigation. |
Tooltips
This property is part of column configuration. Tooltips for cells or columns should be configured on the individual column level. Here is the syntax:
var gridConfig = {
columns: [
{
field: 'value_1',
tooltip : { }, // tooltip configs
},
]}
Enabling Tooltips
Enable header and column tooltips like this:
config = {
columns: [{
field: 'country_name',
tooltip: {
enableHeaderTooltip: true/false
}
}]
};
By default, header tooltips are enabled once the tooltip object is defined. However, users can select to disable/enable header tooltip specifically.
Configuring Header Tooltips
To provide custom text to tooltip in the header, follow the example below:
config = {
columns: [{
field: 'country_name',
tooltip: {
headerTooltip: 'Countries having trade connection.'
}
}]
};
To show the tooltip on hovering a separate info/helper icon in the header, follow the example below:
config = {
columns: [{
field: 'country_name',
tooltip: {
headerTooltip: 'Countries having trade connection',
enableHeaderHelperIcon: true
}
}]
};
Enable/Disable a cell tooltip
Tooltip is automatically enabled once the tooltip object is defined. But to selectively disable or enable cell tooltip, users can follow the example below:
config = {
columns: [{
field: 'country_name',
tooltip: {
enableCellTooltip: true
}
}]
};
If cellTooltip
is not defined, but the tooltip is enabled, then the cell content will be shown in the tooltip.
Conditionally define content for cell tooltip
config = {
columns: [{
field: 'country_name',
tooltip: {
cellTooltip: function(params) {
if (params['country_name']) {
return 'Country : ' + params['country_name'] + ' in ' + params[continent];
} else {
return 'Country name is missing';
}
}
}]
};
Cell info/helper tooltip
Users can enable info/helper tooltip in cells using the following function:
config = {
columns: [{
field: 'country_name',
tooltip: {
cellTooltip: function(params) {
if (params['country_name']) {
return 'Country : ' + params['country_name'] + ' in ' + params[continent];
} else {
return 'Country name is missing';
}
},
enableCellHelperIcon: true
}
}]
};
Here is a list of properties available:
Property Name | Data Type | Description |
---|---|---|
enable |
Boolean | Enables tooltips for the given column. For example: { tooltip : { enable: true; } } |
enableHeaderTooltip |
Boolean | Enables tooltips for the column header. By default it will show the column header value in the tooltip. |
headerTooltip |
String | Text to show when hovered over the header. |
enableHeaderHelperIcon |
Boolean | Enables the helper icon that helps users understand that the column is hoverable. |
enableCellTooltip |
Boolean | Enables tooltips for a cell. By default, tooltip text will be fetched from the cell value. |
cellTooltip |
String, Function | If you pass a string value, it will be shown for all the cells. However, the passing function will give you the ability to render dynamic data as well. Function will provide you with a parameter that will give you access to cell and row data. You have to return a text value that can consist of HTML elements as well. |
enableCellHelperIcon |
Boolean | Similar to head enableHeaderHelperIcon, this will enable the helper icon for all the cells. |
Row Configurations
Allows you to configure rows of the grid. It accepts an object of properties explained below. Here is the syntax:
var gridConfig = {
rowOptions: { key_1: 'value_1' }
}
Setting Row Height
Row height affects all rows, but if the user specifically wants to define header row heights, then they can do so following the example below:
config = {
rowOptions: {
rowHeight: '50px',
headerRowHeight: '20px'
}
}
Styling Row
Users can apply row style. The attributes ‘style’ and/or ‘css’ can be used to style rows.
config = {
rowOptions: {
style: {background: 'green'},
class: ['row-class1','row-class2']
}
}
If row style and cell style conflict, then cell style gets the precedence.
Row Hover
Like styling row and column, hoverStyle and hoverClass accepts both style/css and a function for any rule-based hover. By default, row hover is enabled, but users can override these settings.
config = {
rowOptions: {
hover: {
enable: true,
style: style object/func,
class: css class name/func
}
}
}
Row Selection
If selection is enabled, then on mouse click single row is selected
config = {
rowOptions: {
rowSelection: {
enable: true
}
}
}
Users can also select multiple rows with checkboxes, as follows:
config = {
rowOptions: {
rowSelection: {
showSelectionCheckbox: true/false
}
}
}
Here is the list of properties:
Property Name | Data Type | Description |
---|---|---|
rowHeight |
String, Number | Sets the height of rows in pixels. |
headerRowHeight |
String, Number | Similar to rowHeight but the value gets applied to only the header row. |
class |
Array, Function | Accepts an array of class names in string which will get assigned to all the rows. For example: { class: ['class-1', 'class-2'] } Or you could assign a function which should return an array of class names. This function provides a parameter that provides following properties: rowIndex: Index of the row. values: An object of values for the given rows. |
style |
Object, Function | Helps you customize the appearance of the entire row by passing CSS properties in the form of JSON object like: style: { 'background-color': 'offwhite' } You could also pass a function which should return an object of CSS properties. Similar to the function passed to class, you get an object parameter to access the data of the corresponding cell. |
enableHover |
Boolean | Enables hover state for the entire row. |
hoverClass |
Array, Function | Works exactly like class but the class name will get applied when you hover the row only. |
hoverStyle |
Object, Function | Works exactly like style but the class name will get applied when you hover the row only. |
rowSelection |
Boolean | Enables single row selection. |
selectedRowStyle |
Array | Configure appearance of selected rows. |
showSelectionCheckbox |
Boolean | Enables multiple row selection with checkboxes. |
Conditional Formatting
Users can enable row and column conditional formatting to improve their grids.
Column Conditional Formatting
Column or cell conditional formatting can be achieved using the formatter option, style, by defaultRow or CSS. Formatter gives more flexibility, as shown in the example below: For instance, if a user wants to color red if revenue is less than 1000, color the cell yellow if revenue is between 1000 to 5000 and above that color green.
config = {
columns: [{
field: 'Revenue',
formatter: function(params) {
let value = '$' + formatNumbers(params.cellValue);
let bgColor = '#ff0000';
if (params.cellValue > 1000 && params.cellValue < 5000) {
bgColor = '#ffff00'
} else if (params.cellValue > 5000) {
bgColor = '#00ff00'
}
return '<span style="background-color: "' + bgColor + '/>' + value + '</span>';
}
}]
}
Using style or CSS is more recommended when you are required to set only style conditionally, like this:
config = {
columns: [{
field: 'Revenue',
style: function(params) {
let bgColor = '#ff0000';
if (params.cellValue > 1000 && params.cellValue < 5000) {
bgColor = '#ffff00'
} else if (params.cellValue > 5000) {
bgColor = '#00ff00'
}
return { background-color: bgColor };
}
}]
}
Row Conditional Formatting
Conditional style can also be applied to rows. The RowOptions
has both ‘style’ and ‘css’ attributes that accept functions. If we want to implement the same example above, we want to apply the style to row-level instead of cell-level.
config = {
rowOptions: {
style: function(params) {
let revenue = params.values['Revenue'];
if (revenue < 1000) {
return {background-color: '#ff0000'}
} else if (revenue > 1000 && revenue < 5000) {
return {background-color: '#ffff00'}
} else {
return {background-color: '#00ff00'}
}
}
}
}
The params consist of the following attributes:
values
- consists of all cell values
rowIndex
- index of the row on the current page
node
- DOM node of row
Viewports
FusionGrid provides fice default viewports with default layouts and default breakpoints.
Viewport Name | Min Width | Max Width | Layout Type | Layout Density |
---|---|---|---|---|
mobile | 0 | 550px | card | |
tablet-portrait | 551px | 1023px | card | |
tablet-landscape | 1024px | 1199px | row | compact |
desktop | 1200px | 1399px | row | default |
large-desktop | 1400px | row | comfortable |
json
var gridConfig = {
viewports : { "mobile": { config: { } } }
}
### Viewport object structure
To configure a viewport, users need to mention minScreenWidth
and maxScreenWidth
attributes.
### Override default Viewport configurations
To set your customized viewport configurations, you must mention the viewport name and define your preferred settings. In the example below, for mobile devices layout type is changed from card row.
json
gridConfig = {
viewports: {
'mobile': {
config: {
layout: {
type: 'row'
}
}
}
}
}
Additionally, users can also provide custom viewport and configuration.
json
gridConfig = {
viewports: {
'mobile-portrait': {
minScreenWidth: 0,
maxScreenWidth: 400,
config: {
layout: {
type: 'card',
cardTemplate: function(params) { return some html template;}
}
}
},
'mobile-landscape': {
maxScreenWidth: 600,
config: {
layout: {
type: 'row',
density: 'compact'
}
}
}
}
}
Please note - while defining custom viewport, either min or max width should be mentioned. Otherwise, the viewport will not take into effect.
Each viewport is a key value pair, where key denotes the viewport name and value is a JSON object which consists of the following properties:
Property Name | Data Type | Description |
---|---|---|
minScreenWidth | Number | Assigns the minimum width of the specified view port. |
maxScreenWidth | Number | Assigns the maximum width of the specified view port. |
config | Object | Defines the configuration for the given viewport. You can set layout , pagination , rowOptions and columns . |
Sorting
The following are sorting configurations you can add to your grid.
Column Sorting
Users can enable sorting for each column individually.
config = {
columns: [{
field: 'country_name',
sortable: true
}]
};
The sorting operation triggers when clicking anywhere on the header (apart from other icons like a filter or a tooltip). The first click on the header sorts the column in ascending order. The second click sorts the column in descending order, and a third click clears the sorting.
Enabling or disabling Sorting
Users can choose to enable column sorting by setting the sorting
attribute to true or false.
config = {
columns: [{
field: 'country_name',
sortable: true/false
}]
};
config = {
columns: [{
field: 'country_name',
sortable: {
enable: true/false
}
}]
};
Pre-defined Sorting
Apply sort to specific columns by mentioning the applySort
attribute to either asc
or desc
order.
config = {
columns: [{
field: 'Revenue',
sortable: {
applySort: 'desc'
}
}]
};
Attribute | Type | Description |
---|---|---|
sortable | boolean | Enables Column sorting. |
applySort | boolean | Choose to sort in asc or desc order . |
Events
All event listeners can be defined in JSON files. And this is the recommended way.
config = {
'events': {
'initialized': function(eventObj) { console.log('Grid Initialized - but not yet rendered'); },
'rendered': function(eventObj) { console.log('Grid rendered'); },
}
}
Filters
You can apply four different types of filters to your columns; column conditional filter, value filter, custom filter, and quick search filter.
Column Conditional Filter
Apply column filters by enabling them like this:
config = {
columns: [{
field: 'Revenue',
filter: true
}]
};
Or like this:
config = {
columns: [{
field: 'Revenue',
filter: {
conditionalFilter: {
enable: true
}
}
}]
};
The following are the conditions that users can apply to the filters:
String Type Columns | Number Type Columns | Datetime Type Columns |
---|---|---|
Equals | Equals | Equals |
Not equals | Not equals | Not equals |
Contains | Less than | Is before |
Does not contain | Less than or equal to | Is on and before |
Starts with | Greater than | Is after |
Ends with | Greater than or equal to | Is on and after |
Is empty | Between | Between |
Is not empty | Is empty | Is empty |
Is not empty | Is not empty |
Enable Multiple Filters
Users can enable multiple filters per column by following the example below:
config = {
columns: [{
field: 'Revenue',
filter: {
conditionalFilter: {
enableMultiFilter: true
}
}
}]
};
Users can combine multiple filters per column using the and
/or
operations.
Show the Apply and Cancel buttons
To enable the Apply and Cancel buttons on your filters, make sure to enable showApplyCancel
like the example below:
config = {
columns: [{
field: 'Revenue',
filter: {
conditionalFilter: {
showApplyCancel: true
}
}
}]
};
Value Filters
Enable value filters to show a list of all available values for a particular column. To enable a value filter, follow the example below:
config = {
columns: [{
field: 'Category',
filter: {
valueFilter: {
enable: true
}
}
}]
};
Enabling Multi-select mode
Users can enable the multiple selection operation to use checkboxes to select multiple columns or use the ‘Select All’ operation to select all columns.
config = {
columns: [{
field: 'Category',
filter: {
valueFilter: {
enableMultiSelect: true
}
}
}]
};
Enabling the search box
Users can also enable a search box to search for values like shown in the example below:
config = {
columns: [{
field: 'Category',
filter: {
valueFilter: {
enableMultiSelect: true,
enableSearch: true
}
}
}]
};
Custom Filters
Users can customize filters by defining conditions to apply to your filter. Follow the example below:
config = {
columns: [{
field: 'Nationality',
filter: {
customFilter: {
options: [{
displayText: 'English Premier League',
filterFunc: function(row, column) {
return ['Manchester Utd', 'Liverpool', 'Arsenal'].indexOf(row[columns['Nationality']]) >= 0;
}
}, {
displayText: 'Bundesliga',
filterFunc: function(row, column) {
return ['Bayern Munich', 'Borussia Dortmund'].indexOf(row[columns['Nationality']]) >= 0;
}
}, ...]
}
}
}]
};
Each option has two configurations a display text and a filter function.
Property Name | Data Type | Description |
---|---|---|
filter | Boolean | Applies filter to columns when enabled. |
conditionalFilter | Boolean | Enables conditional filtering |
enableMultiFilter | Boolean | Enables multiple filtering per column |
valueFilter | Boolean | Enables filtering per values |
enableMultiSelect | Boolean | Enables multiple value selection |
enableSearch | Boolean | Enables the search bar |
showApplyCance; | Boolean | Enables the Apply and Cancel buttonsr |
Specify Defaults
Specify your preferences by setting your default common column configurations, using the defaultColumnOptions
, like this:
config = {
defaultColumnOptions: {
width: 300,
enableHover: true,
hoverClass: 'col-hover'
},
columns: [{ field: 'Country' },{ 'Continent' },{ 'Revenue' }]
}
The difference between defaultColumnOptions and columns is: columns allow you to configure on an individual column level while defaultColumnOptions allows you to define it on the global level. All the properties available in columns are available in defaultColumnOptions as well with the only exceptions of field and type.