UIBootgrid
The UIBootgrid system is a wrapper around Tabulator and provides a generic table system that is reusable on all pages requiring data listing and manipulation.
Setup
To get started, see Using grids module & plugin. The example will show you how to get started with a minimal grid setup and how this front-end code ties to the controller layer.
Basic Layout
Since the controller layer defines standardized output and expects standardized input, it’s possible to construct and feed a grid by simply defining a set of endpoints as explained in the setup:
$("#{{formGridAddress['table_id']}}").UIBootgrid(
{
search:'/api/gridexample/settings/search_item/',
get:'/api/gridexample/settings/get_item/',
set:'/api/gridexample/settings/set_item/',
add:'/api/gridexample/settings/add_item/',
del:'/api/gridexample/settings/del_item/',
toggle:'/api/gridexample/settings/toggle_item/',
info:'/api/gridexample/settings/info'
}
);
You can use the browser developer tool to inspect the request/response structures of each
operation. For example, the search endpoint looks like this:
Request:
{
"current": 1,
"rowCount": 50,
"sort": {}
}
Response:
{
"rows": [
{
"uuid": "3b4e949d-443b-4127-a709-1e41589db462",
...
},
...
],
"rowCount": 1,
"total": 1,
"current": 1
}
Note
info endpoints are not used very often (and can safely be omitted),
these are mainly intended as simple trigger to display an info dialog.
Configuration Reference
The UIBootgrid initialization object starts with the CRUD methods as stated above, but
the whole structure contaions a lot of options to modify the behavior to fit your purpose.
The top-level options are layed out as follows:
config
├── search
├── get
├── set
├── add
├── del
├── toggle
├── info
├── options
│ ├── ...
│ ├── ...
│ └── ...
├── commands
│ ├── ...
│ └── ...
├── tabulatorOptions
├── ...
└── ...
options
General settings for bootgrid behavior
Property |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Defines the property in the data that is used for indexing into the grid. Since most
model data is uniquely identified through a UUID, this property defaults to
|
|
|
|
Disables in-grid vertical scrolling behavior. Setting this to |
|
|
|
Whether sorting should be enabled. Sorting is triggered through header clicks. |
|
|
|
An array of numbers that defines the selection of row counts a user can select.
The special value |
|
|
|
Formatters for values in cells. See options.formatters. |
|
|
|
Formatters for the headers of columns. See options.headerFormatters. |
|
|
|
A key-value pair representing status colors. For example: statusMapping: {
0: "fw-pass",
1: "fw-nat",
2: "fw-block",
}
To use this, each row must contain a |
|
|
|
Specify one or more custom sorter functions indexed by key. To instruct
a column to use this sorter, set the |
|
|
|
Request handler callback function that’s executed before the AJAX call. The function expects 1 parameter: |
|
|
|
Response handler callback function that’s executed after AJAX response.
This function expects 1 parameter: |
|
|
|
Determines if the grid reset button should be rendered. The grid locally persists certain changes by default, such as column resizes, sorting behavior etc. This button clears the persistence and resets the grid to all defaults. |
|
|
|
Allows modifying search behaviour of the grid. Currently only “delay” is defined and set to 1000ms by default. Delay is the amount of time waiting before reloading the grid after search. |
|
|
|
If the action bar, pagination and footer should be rendered. |
|
|
|
If disabled, ignores any CRUD endpoint defined. Use the replace(rows) or
append(rows) functions to add data to the grid yourself. If disabled, any sorting,
filtering or pagination will happen locally, as all data is expected to be present
in the grid. You can use the If enabled, uses the defined CRUD enpoints to fetch/filter/sort and modify the data. |
|
|
See description |
Ajax configuration used in all ajax calls. The defaults are: {
method: "POST",
dataType: "json",
headers: {
"Content-type": "application/json;charset=utf8"
}
}
Override for advanced purposes. |
|
|
|
If this grid is allowed to split longer lines into newlines, creating variable height grid rows. Use this if the cell content should always be visible, otherwise, the content will be cut off with an ellipsis and dynamically assigned a tooltip so hovering over the data will show the full content. |
|
|
|
function handler which will be called before an edit dialog is being displayed, can
be used to change the otherwise static dialogs. Should return a $.Deferred() object.
(e.g. |
|
|
|
Enable or disable the virtual rendering mode of the grid. See the Tabulator docs. In essence this option makes sure that not all rows are rendered by default, but are rendered on the fly as they are needed when the user scrolls down/up. This makes it possible to render an extremely large amount of rows with very little performance impact. When using this options, keep in mind that each row may not be available in the DOM
yet at any given time for direct referencing in code. Therefore, the proper
|
|
|
|
Whether individual rows should be selectable through a checkbox in a left-frozen column. |
|
|
|
Whether multiple rows may be selected for actions
( |
|
|
|
Ignores |
|
|
|
Whether rows should be selectable by clicking in any of the row cells. Keep in mind that in UX terms, this makes it difficult for users to select values in a grid for copy+pasting purposes. |
|
|
|
Enable/disable the batching of the |
|
|
|
Default maximum batch side for |
|
|
|
Enable/disable the batching of the |
|
|
|
Default maximum batch side for |
|
|
|
Set this value to a If we came from a different page, the In most cases, if triggering an edit on referral is necessary, |
|
|
|
Same behaviour as The standardized method to get this value is |
|
|
|
Disables persistent storage and resizable columns so the dimensions of the grid are predictable at all times. |
|
|
|
If there is an element below the grid that should be visible at all times (no page scrollbar), you can specify this element here so the grid height calculation takes the height of this element into account. |
options.formatters
Formatters are functions that are executed for each cell whose column has a formatter specified and determine the value that is presented to the user in the cell. Formatters allow you to manipulate the data fetched from the controller into a format that is more easily digestable for a user.
The formatters option is an object that contains key - function pairs,
where each key corresponds to the formatter value in the grid form as explained in
Define dialog items.
For example:
formatters: {
myformatter: function (column, row, onRendered) {
return row[column.id];
}
}
The above example simply returns the value of the row without modifications.
The column parameter is an object that contains the id and the visibility
status of the column.
The row parameter is an object that contains the data for this row.
The onRendered parameter is a callback function that allows you to execute a function
when the cell has been rendered. For example:
formatters: {
myformatter: function (column, row, onRendered) {
onRendered((cell) => {
console.log(`grid cell has been rendered. cell data: ${cell.getData()}`);
})
return row[column.id];
}
}
This is useful if you want to bind event handlers to the rendered DOM element, or do work if the cell contains more complex objects such as graphs that are initialized asynchronously.
The callback function expects a single parameter, cell, which you can access to get the
cell object
options.headerFormatters
Functionally equivalent to options.formatters, but applied to the column header value instead.
By default it’s not necessary to specify a headerFormatter tag in the grid_view
tag of a form, as the keys match to the row keys. For example:
headerFormatters: {
enabled: function(column) {
return '<i class="fa-solid fa-fw fa-check-square" data-toggle="tooltip" title="{{ lang._('Enabled') }}"></i>';
}
}
The above example will match on the enabled row key and return an icon with a tooltip
showing the translated value of the column title.
The function expects only a single parameter, column, which is an object containing
id, visible, title.
commands
The Commands column is a special column that is situated frozen on the right side of the grid
to ease access regardless of scroll position. This column contains buttons that are linked to actions
that can be defined/extended in this configuration section.
Besides the commands defined in the commands column, there are also command buttons placed below the grid
which are linked to actions that are not related to one grid row specifically, such as add or
delete-selected. These buttons can also be defined in the command structure, but with the
footer property set to true.
The following commands are built-in by default and are rendered automatically based on their respective CRUD endpoint requirements:
add. Requiresget,set.edit. Requiresget,set.delete. Requiresdel.copy. Requiresget,sets.info. Requiresinfo,toggle. Requirestoggle.enable-selected. Requirestoggle(SeebatchToggleoption).disable-selected. Requirestoggle(SeebatchToggleoption).delete-selected. Requiresdel(SeebatchDeleteoption).
You may override a specific property of the above built-in commands, as the commands object
is deeply merged, e.g.:
edit: {
sequence: 200
}
Will preserve all edit command options, but change the sequence from its default of 100
to 200.
Extra commands can be defined in the top-level commands object. The structure of a command starts
with a unique key and contains an object with the following schema:
Property |
Type |
Required |
Description |
|---|---|---|---|
|
|
No |
A function that is executed on command click. Function signature is |
|
|
No |
Translated title to be shown as a tooltip. If the title depends on state, this property can also be a function. If it’s a function, the Cell object is passed as a parameter. |
|
|
No |
An optional array of strings that define if this command depends on one or more CRUD actions.
For example, the default |
|
|
No |
A number to control how the button is ordered amongst the other buttons. |
|
|
No |
Whether this command should be rendered in the footer or as part of a row. |
|
|
No |
Whether this command should be rendered as part of the primary button container.
Only relevant when |
|
|
Yes |
Icon class added to the |
|
|
No |
A function that, if defined, must return true or false and determines if this command
should be rendered. The Cell object is only passed in if |
|
|
No |
A function that runs after the element including event bindings have been rendered.
This allows the caller to override the behavior of the command. The element is bound to the function
and can be access through This function can be used to bind the rendered command DOM element to other system components, such as $.SimpleFileUploadDlg. |
There are default commands built-in to the UIBootgrid framework that work in tandem with the default controller actions to facilitate basic CRUD behavior.
For advanced use cases, you can also call the built-in command methods directly. For an
example, see the
Unbound overrides template
Methods
Methods on UIBootgrid can be called through the JQuery bootgrid API:
$('#<grid-id>').bootgrid('<method>', ...params);
append(rows)
Appends rows to the grid. This is a lot slower than replace(rows). Since most of the sorting/filtering
logic happens remotely, replace should be the preferred method to manipulate data
in the grid.
replace(rows)
Replaces all data in the grid by rows. Use this function if ajax: false to set data in the grid.
getTable()
Gets the Tabulator grid instance bound to this UIBootgrid.
clear()
Clears any data in the grid.
reload()
Reload the grid. Triggers a new AJAX request. Always use this
getRowCount()
Gets currently selected row count
getSelectedRows()
Gets the datakey values of the currently selected rows
getCurrentRows()
Gets all datakey values of all rows in the table
getCurrentPage()
Gets current paginated page.
destroy()
Destroy the grid
setColumns(columns)
Enable the visibility of columns. The columns parameter expects an
array of column IDs.
unsetColumns(columns)
Disable the visibility of columns. The columns parameter expects an
array of column IDs.
search(value, event)
Search for value in the grid (triggering an AJAX request if ajax: true).
select(ids)
Programatically select rows. Expects an array of datakey strings.
getSearchPhrase()
Get current search phrase.
setPersistence(value)
Enable or disable grid persistence (column setup in local storage). Expects a boolean.
Other components
If an apply button is rendered on the page through $.SimpleActionButton, :UIBootgrid
will automatically signal to that element to prompt the user to apply if something in the grid changed,
e.g. when a row has been edited. Internally it does this by simply calling $(document).trigger("settings-changed");.