General
There are two ways to populate jQuery Bootgrid. Either you use the server-side way (e.g. a REST service) for querying a dynamic data source like a database or you use the client-side way for simple in-memory data visualization.
To use the client-side way you need almost no configuration. Just add your rows via HTML or use the append
method to append rows dynamically (see here).
For using the server-side way you must set at least the ajax
option to true
and pass an URL to the url
option (see here).
All settings can also be set via the data API on the table
tag for general settings and th
tags for column specific settings.
Add data-toggle="bootgrid"
to your table to initialize jQuery Bootgrid without writing any line of JavaScript code.
General Settings
Name | Description | Type |
---|---|---|
navigation | Enables or disables header and/or footer. Default value is 3 .0 for none, 1 for header, 2 for footer and 3 for both. |
Integer |
padding | Defines the padding of the pagination on both sides (right & left). Default value is 2 . |
Integer |
columnSelection | Enables or disables the dropdown box to hide/show columns. Default value is true . |
Boolean |
rowCount | An Array of Integer which will be shown in the dropdown box to choose the row count. Default value is [10, 25, 50, -1] . -1 means all. When passing an Integer value the dropdown box will disapear. |
Array or Integer |
selection | Enables row selection (to enable multi selection see also multiSelect ). Default value is false . |
Boolean |
multiSelect | Enables multi selection (selection must be set to true as well). Default value is false . |
Boolean |
sorting | Enables sorting (to enable multi sorting see also multiSort ). Default value is true . |
Boolean |
multiSort | Enables multi sorting (sorting must be set to true as well). Default value is false . |
Boolean |
rowSelect | Enables entire row click selection (sorting must be set to true as well). Default value is false . 1.1.0 |
Boolean |
keepSelection | Defines whether the row selection is saved internally on filtering, paging and sorting (even if the selected rows are not visible). 1.1.0 | Boolean |
ajax |
Enables server-side population (by setting this option to true you also have to pass an
URL to url for your data service). Default value is false .
|
Boolean |
post |
Enriches the request object with additional properties. Either a PlainObject or a
Function that returns a PlainObject can be passed. Default value is {} . Obsolete Use instead requestHandler !
|
PlainObject or Function |
url |
Sets the data URL to a data service (e.g. a REST service). Either a String or a
Function that returns a String can be passed. Default value is "" .
|
String or Function |
caseSensitive | Defines whether the search is case sensitive or insensitive. Default value is true . 1.1.0 |
Boolean |
requestHandler | Transforms the JSON request object in what ever is needed on the server-side implementation. Default value is function (request) { return request; } . 1.1.0 |
Function |
responseHandler | Transforms the response object into the expected JSON response object. Default value is function (response) { return response; } . 1.1.0 |
Function |
Ajax Settings
Ajax request settings that shall be used for server-side communication.
All setting except data, error, success and url can be overridden. For the full list of settings go to jQuery.ajax.
Name | Description | Type |
---|---|---|
method | Specifies the HTTP method which shall be used when sending data to the server. Default value is POST . 1.2.0 NEW |
String |
Example
The following example shows how to override ajax settings.
$("#grid").bootgrid({ ajaxSettings: { method: "GET", cache: false } });
Search Settings
General search settings to configure the search field behaviour.
Name | Description | Type |
---|---|---|
delay | The time in milliseconds to wait before search gets executed. Default value is 250 . 1.2.0 NEW |
Integer |
characters | The characters to type before the search gets executed. Default value is 1 . 1.2.0 NEW |
Integer |
Example
The following example shows how to override search settings.
$("#grid").bootgrid({ searchSettings: { delay: 100, characters: 3 } });
Status Mappings
Specifies the mapping between status and contextual classes to color rows.
Name | Description | Type |
---|---|---|
0 | Specifies a successful or positive action. Default value is success . 1.2.0 NEW |
String |
1 | Specifies a neutral informative change or action. Default value is info . 1.2.0 NEW |
String |
2 | Specifies a warning that might need attention. Default value is warning . 1.2.0 NEW |
String |
3 | Specifies a dangerous or potentially negative action. Default value is danger . 1.2.0 NEW |
String |
Example
The following example shows how to extend the status mappings.
$("#grid").bootgrid({ statusMappings: { 4: "wrong" } });
Converters
Built-in converters for a better sorting experience and localization.
Name | Description |
---|---|
numeric | A numeric converter that converts String to Number and vice versa. |
string | The default converter (no conversion; takes the String as it is). |
Example for custom converter
It´s very simple to create a custom converter. The converter consists of two methods: from
and to
. from
converts a String
to a desired type.
to
instead converts a type into a representational String
.
In the example below you can see how easy it is to integrate Moment.js for better datetime visualization and sorting.
$("#grid").bootgrid({ converters: { datetime: { from: function (value) { return moment(value); }, to: function (value) { return value.format("lll"); } } } });
Keep in mind when using Moment.js to select one of the ISO-8601 datetime formats recommended here when populating jQuery Bootgrid in order to avoid strange behaviour.
Formatters
Formatters are perfect to manipulate the visualization of data cells. They´re fast and easy to implement, but see yourself in the example below.
How to create a formatter
A formatter is nothing else than a Function
that gets invoked on data cell rendering. this
is mapped to the current Bootgrid instance. The formatter return a HTML String
. Use the loaded.rs.jquery.bootgrid
event to bind custom events to your controls rendered by a formatter.
$("#grid").bootgrid({ formatters: { commands: function (column, row) { /* "this" is mapped to the grid instance */ return "html code"; } } });
Be creative by adding your own templates, labels or styles.
Labels
All labels can be set and overridden on initialization respectively.
Name | Description | Default Value |
---|---|---|
all | This label is used in the row count selection box. | All |
infos | This label is used by default in the footer section to provide helpful informations regarding the table content. | Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries |
loading | This label shows up in async scenarios while data is loading. | Loading... |
noResults | This message is shown in the table content part when no data rows are available. | No results found! |
refresh | Tooltip for the refresh button. | Refresh |
search | Placeholder text for the search field. | Search |
Example
See in the following example how to override default label values or see it here in action.
$("#grid").bootgrid({ labels: { noResults: "where are my results" } });
Styling
All CSS classes can be set and overridden on initialization respectively.
Name | Description | Default Value |
---|---|---|
actions | actions btn-group | |
center | text-center | |
columnHeaderAnchor | column-header-anchor | |
columnHeaderText | text | |
dropDownItem | dropdown-item | |
dropDownItemButton | dropdown-item-button | |
dropDownItemCheckbox | dropdown-item-checkbox | |
dropDownMenu | dropdown btn-group | |
dropDownMenuItems | dropdown-menu pull-right | |
dropDownMenuText | dropdown-text | |
footer | bootgrid-footer container-fluid | |
header | bootgrid-header container-fluid | |
icon | icon glyphicon | |
iconColumns | glyphicon-th-list | |
iconDown | glyphicon-chevron-down | |
iconRefresh | glyphicon-refresh | |
iconUp | glyphicon-chevron-up | |
infos | infos | |
left | text-left | |
pagination | pagination | |
paginationButton | button | |
responsiveTable | CSS class to select the parent div which activates responsive mode. 1.1.0 | table-responsive |
right | text-right | |
search | search form-group | |
selectCell | select-cell | |
selectBox | select-box | |
searchField | search-field form-control | |
selected | CSS class to highlight selected rows. 1.1.0 | active |
sortable | sortable | |
table | bootgrid-table table |
Templates
All templates can be set and overridden on initialization respectively.
Name | Description | Context-sensitive Placeholder |
---|---|---|
actionButton | {{ctx.text}} , {{ctx.content}} |
|
actionDropDown | {{ctx.content}} |
|
actionDropDownItem | {{ctx.action}} , {{ctx.text}} |
|
actionDropDownCheckboxItem | {{ctx.checked}} , {{ctx.label}} , {{ctx.name}} |
|
actions | ||
body | ||
cell | {{ctx.content}} , {{ctx.css}} |
|
footer | {{ctx.id}} |
|
header | {{ctx.id}} |
|
headerCell | {{ctx.column}} , {{ctx.icon}} , {{ctx.sortable}} |
|
icon | {{ctx.iconCss}} |
|
infos | ||
loading | {{ctx.columns}} |
|
noResults | {{ctx.columns}} |
|
pagination | ||
paginationItem | {{ctx.css}} , {{ctx.text}} , {{ctx.page}} |
|
rawHeaderCell | {{ctx.content}} , {{ctx.css}} |
|
row | {{ctx.cells}} |
|
search | ||
select | {{ctx.type}} , {{ctx.value}} |
Dynamic Placeholder
As you may already have noticed, some templates and labels contain strange content parts like {{ctx.icon}}
. These are dynamic placeholders which will be replaced upon rendering. There are three different types of placeholders.
ctx
is a dynamic context-sensitive container, whereas css
(CSS container) and lbl
(label container) are more or less static containers (they are linked directly to the CSS and label settings).
Due to technical constraints CSS and label settings should not be nested because it would lead to strange indication errors.
Column Settings
Name | Description | Type |
---|---|---|
align | Sets the text alignment of table body cells. Default value is left . Possible values are left , center and right . |
String |
converter | Specifies a converter by using the name of the desired converter. The default value is string . |
String |
cssClass | Sets the CSS class of table body cells. The default value is "" . 1.1.0 |
String |
formatter | Specifies a formatter by using the name of the desired formatter. Formats the table body cell content. Default value is null . |
String |
headerAlign | Sets the text alignment of table header cells. Default value is left . Possible values are left , center and right . |
String |
headerCssClass | Sets the CSS class of table header cell. The default value is "" . 1.1.0 |
String |
id | Sets the column id. Required | String |
identifier | For marking a column as unique identifier. Default value is false . |
Boolean |
order | Specifies the sort order. Default value is "" . Possible values are "" , asc and desc . |
String |
searchable | Enables searching. The default value is true . 1.1.0 |
Boolean |
sortable | Enables sorting. Default value is true . |
Boolean |
type | For description see converter . Obsolete Use instead converter ! |
String |
visible | Sets the visibility of a column. Default value is true . |
Boolean |
visibleInSelection | Sets the visibility of the column selection box item for a specific column. Default value is true . 1.3.0 NEW |
Boolean |
Column settings can only be set via data API at the moment.
Events
Name | Description | Parameters |
---|---|---|
appended | Fires after appending row(s). | Event e,
Array appendedRows |
cleared | Fires after calling clear . |
Event e,
Array affectedRows |
click | Fires after clicking on table body rows. 1.1.0 | Event e,
Array columns,
PlainObject row |
deselected | Fires after deselecting row(s). | Event e,
Array deselectedRows |
initialize | Fires before initialization. | Event e |
initialized | Fires after initialization. | Event e |
load | Fires before loading data. | Event e |
loaded | Fires after data is loaded. | Event e |
removed | Fires after removing row(s). | Event e,
Array removedRows |
selected | Fires after selecting row(s). Note: Provides only new selected rows not all. | Event e,
Array selectedRows |
Example
In the following example you can see how to subscribe to the plugin specific events.
$("#grid").bootgrid() .on("load.rs.jquery.bootgrid", function (e) { /* your code goes here */ });
Always append the plugin namespace .rs.jquery.bootgrid
to the event name in order to subscribe events.
Methods
Name | Description | Parameters | Return Type |
---|---|---|---|
append | Appends new rows. This method is chainable. | Array rows |
jQuery |
clear | Removes all rows. This method is chainable. | jQuery |
|
deselect | Deselects rows by ids. Deselects all visible rows if no ids are provided. In server-side scenarios only visible rows are deselectable. 1.1.0 | Array rowIds |
jQuery |
destroy | Removes the control functionality completely and transforms the current state to the initial HTML structure. This method is chainable. | jQuery |
|
reload | Triggers a data reload (only supported for server-side scenarios when ajax is set to true ). This method is chainable. |
jQuery |
|
remove | Removes rows by the given row ids or removes selected rows if no ids were passed. This method is chainable. | Array rowIds |
jQuery |
search | Searches in all visible columns for the given phrase. If no argument is passed, it will reset the search. This method is chainable. | String {phrase} |
jQuery |
select | Selects rows by ids. Selects all visible rows if no ids are provided. In server-side scenarios only visible rows are selectable. 1.1.0 | Array rowIds |
jQuery |
sort | Sorts rows by the given dictionary. If no argument is passed, it will reset sorting. This method is chainable. | PlainObject {dictionary} |
jQuery |
Example
The following example shows how to invoke methods.
/* Single invoke */ $("#grid").bootgrid("search", "serach phrase"); /* Multi invoke (chaining) */ $("#grid").bootgrid("destroy").bootgrid("search", "serach phrase");
Properties
Please notice properties return values only for the first grid instance. This will probably enhanced in the next version.
Name | Description | Return Type |
---|---|---|
getColumnSettings | Gets a list of the column settings. 1.2.0 NEW | Array |
getCurrentPage | Gets the current page index. 1.2.0 NEW | Integer |
getCurrentRows | Gets the current rows. 1.2.0 NEW | Array |
getRowCount | Gets a number represents the row count per page. 1.2.0 NEW | Integer |
getSearchPhrase | Gets the actual search phrase. 1.2.0 NEW | String |
getSelectedRows | Gets the complete list of currently selected rows. 1.2.0 NEW | Array |
getSortDictionary | Gets the sort dictionary which represents the state of column sorting. 1.2.0 NEW | PlainObject |
getTotalPageCount | Gets a number represents the total page count. 1.2.0 NEW | Integer |
getTotalRowCount | Gets a number represents the total row count. 1.2.0 NEW | Integer |
Example
The following example shows how to call properties.
$("#grid").bootgrid("getTotalRowCount");