bootstrap table

The table options are defined in jQuery.fn.bootstrapTable.defaults.

Name

Attribute

Type

Default

Description

-data-toggleString'table'Activate bootstrap table without writing JavaScript.
classesdata-classesString'table table-hover'The class name of table. By default, the table is bordered, you can add 'table-no-bordered' to remove table-bordered style.
sortClassdata-sort-classStringundefinedThe class name of the td elements which are sorted.
heightdata-heightNumberundefinedThe height of table.
undefinedTextdata-undefined-textString'-'Defines the default undefined text.
stripeddata-stripedBooleanfalseTrue to stripe the rows.
sortNamedata-sort-nameStringundefinedDefines which column will be sorted.
sortOrderdata-sort-orderString'asc'Defines the column sort order, can only be 'asc' or 'desc'.
sortStabledata-sort-stableBooleanfalseTrue to get a stable sorting. We will add _position property to the row.
iconsPrefixdata-icons-prefixString'glyphicon'Defines icon set name ('glyphicon' or 'fa' for FontAwesome). By default 'glyphicon' is used.
iconSizedata-icon-sizeStringundefinedDefines icon size:
  • undefined => btn
  • xs => btn-xs
  • sm => btn-sm
  • lg => btn-lg
buttonsClassdata-buttons-classString'default'Defines the Bootstrap class (added after 'btn-') of table buttons: EX: 'primary', 'danger', 'warning'...
iconsdata-iconsObject{
  paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  refresh: 'glyphicon-refresh icon-refresh',
  toggle: 'glyphicon-list-alt icon-list-alt',
  columns: 'glyphicon-th icon-th',
  detailOpen: 'glyphicon-plus icon-plus',
  detailClose: 'glyphicon-minus icon-minus'
}
Defines icons used in the toolbar, pagination, and details view.
columns-Array[]The table columns config object, see column properties for more details.
data-Array[]The data to be loaded.
dataFielddata-data-fieldString'rows'Key in incoming json containing rows data list.
ajaxdata-ajaxFunctionundefinedA method to replace ajax call. Should implement the same API as jQuery ajax method.
methoddata-methodString'get'The method type to request remote data.
urldata-urlStringundefinedA URL to request data from remote site. 
Note that the required server response format is different depending on whether the 'sidePagination' option is specified. See the following examples:
cachedata-cacheBooleantrueFalse to disable caching of AJAX requests.
contentTypedata-content-typeString'application/json'The contentType of request remote data.
dataTypedata-data-typeString'json'The type of data that you are expecting back from the server.
ajaxOptionsdata-ajax-optionsObject{}Additional options for submit ajax request. List of values: http://api.jquery.com/jQuery.ajax.
queryParamsdata-query-paramsFunctionfunction(params) {
return params;
}
When requesting remote data, you can send additional parameters by modifying queryParams. If queryParamsType = 'limit', the params object contains: 
limit, offset, search, sort, order Else, it contains: 
pageSize, pageNumber, searchText, sortName, sortOrder. 
Return false to stop request.
queryParamsTypedata-query-params-typeString'limit'Set 'limit' to send query params width RESTFul type.
responseHandlerdata-response-handlerFunctionfunction(res) {
return res;
}
Before load remote data, handler the response data format, the parameters object contains: 
res: the response data.
paginationdata-paginationBooleanfalseTrue to show a pagination toolbar on table bottom.
paginationLoopdata-pagination-loopBooleantrueTrue to enable pagination continuous loop mode.
onlyInfoPaginationdata-only-info-paginationBooleanfalseTrue to show only the quantity of the data that is showing in the table. It needs the pagination table options is set to true.
sidePaginationdata-side-paginationString'client'Defines the side pagination of table, can only be 'client' or 'server'. Using 'server' side requires either setting the 'url' or 'ajax' option. 
Note that the required server response format is different depending on whether the 'client' or 'server' option is specified. See the following examples:
pageNumberdata-page-numberNumber1When set pagination property, initialize the page number.
pageSizedata-page-sizeNumber10When set pagination property, initialize the page size.
pageListdata-page-listArray[10, 25, 50, 100]When set pagination property, initialize the page size selecting list. If you include the 'All' option, all the records will be shown in your table.
selectItemNamedata-select-item-nameString'btSelectItem'The name of radio or checkbox input.
smartDisplaydata-smart-displayBooleantrueTrue to display pagination or card view smartly.
escapedata-escapeBooleanfalseEscapes a string for insertion into HTML, replacing &<>"`, and ' characters.
searchdata-searchBooleanfalseEnable the search input.
searchOnEnterKeydata-search-on-enter-keyBooleanfalseThe search method will be executed until the Enter key is pressed.
strictSearchdata-strict-searchBooleanfalseEnable the strict search.
searchTextdata-search-textString''When set search property, initialize the search text.
searchTimeOutdata-search-time-outNumber500Set timeout for search fire.
trimOnSearchdata-trim-on-searchBooleantrueTrue to trim spaces in search field.
showHeaderdata-show-headerBooleantrueFalse to hide the table header.
showFooterdata-show-footerBooleanfalseTrue to show the summary footer row.
showColumnsdata-show-columnsBooleanfalseTrue to show the columns drop down list.
showRefreshdata-show-refreshBooleanfalseTrue to show the refresh button.
showToggledata-show-toggleBooleanfalseTrue to show the toggle button to toggle table / card view.
showPaginationSwitchdata-show-pagination-switchBooleanfalseTrue to show the pagination switch button.
minimumCountColumnsdata-minimum-count-columnsNumber1The minimum number of columns to hide from the columns drop down list.
idFielddata-id-fieldStringundefinedIndicate which field is an identity field.
uniqueIddata-unique-idStringundefinedIndicate an unique identifier for each row.
cardViewdata-card-viewBooleanfalseTrue to show card view table, for example mobile view.
detailViewdata-detail-viewBooleanfalseTrue to show detail view table.
detailFormatterdata-detail-formatterFunctionfunction(index, row, element) {
return '';
}
Format your detail view when detailView is set to true. Return a String and it will be appended into the detail view cell, optionally render the element directly using the third parameter which is a jQuery element of the target cell.
searchAligndata-search-alignString'right'Indicate how to align the search input. 'left', 'right' can be used.
buttonsAligndata-buttons-alignString'right'Indicate how to align the toolbar buttons. 'left', 'right' can be used.
toolbarAligndata-toolbar-alignString'left'Indicate how to align the custom toolbar. 'left', 'right' can be used.
paginationVAligndata-pagination-v-alignString'bottom'Indicate how to align the pagination. 'top', 'bottom', 'both' (put the pagination on top and bottom) can be used.
paginationHAligndata-pagination-h-alignString'right'Indicate how to align the pagination. 'left', 'right' can be used.
paginationDetailHAligndata-pagination-detail-h-alignString'left'Indicate how to align the pagination detail. 'left', 'right' can be used.
paginationPreTextdata-pagination-pre-textString'‹'Indicate the icon or text to be shown in the pagination detail, the previous button.
paginationNextTextdata-pagination-next-textString'›'Indicate the icon or text to be shown in the pagination detail, the next button.
clickToSelectdata-click-to-selectBooleanfalseTrue to select checkbox or radiobox when clicking rows.
singleSelectdata-single-selectBooleanfalseTrue to allow checkbox selecting only one row.
toolbardata-toolbarString | NodeundefinedA jQuery selector that indicates the toolbar, for example:
#toolbar, .toolbar, or a DOM node.
checkboxHeaderdata-checkbox-headerBooleantrueFalse to hide check-all checkbox in header row.
maintainSelecteddata-maintain-selectedBooleanfalseTrue to maintain selected rows on change page and search.
sortabledata-sortableBooleantrueFalse to disable sortable of all columns.
silentSortdata-silent-sortBooleantrueSet false to sort the data silently. This options works when the sidePagination option is set to server.
rowStyledata-row-styleFunction{}The row style formatter function, takes two parameters: 
row: the row record data.
index: the row index.
Support classes or css. Example usage:
function rowStyle(row, index) {
  return {
    classes: 'text-nowrap another-class',
    css: {"color": "blue", "font-size": "50px"}
  };
}
rowAttributesdata-row-attributesFunction{}The row attribute formatter function, takes two parameters: 
row: the row record data.
index: the row index.
Support all custom attributes.
customSearchdata-custom-searchFunction$.noopThe custom search function is executed instead of built-in search function, takes one parameters: 
text: the search text.
Example usage:
function customSearch(text) {
            //Search logic here.
            //You must use `this.data` array in order to filter the data. NO use `this.options.data`.
        }
customSortdata-custom-sortFunction$.noopThe custom sort function is executed instead of built-in sort function, takes two parameters: 
sortName: the sort name.
sortOrder: the sort order.
Example usage:
function customSort(sortName, sortOrder) {
            //Sort logic here.
            //You must use `this.data` array in order to sort the data. NO use `this.options.data`.
        }
localedata-localeStringundefinedSets the locale to use (i.e. 'fr-CA'). Locale files must be pre-loaded. Allows for fallback locales, if loaded, in the following order:
  1. First tries for the locale as specified,
  2. Then tries the locale with '_' translated to '-' and the region code upper cased,
  3. Then tries the the short locale code (i.e. 'fr' instead of 'fr-CA'),
  4. And finally will use the last locale file loaded (or the default locale if no locales loaded).
If left undfined or an empty string, uses the last locale loaded (or 'en-US' if no locale files loaded).
footerStyledata-footer-styleFunction{}The footer style formatter function, takes two parameters: 
row: the row record data.
index: the row index.
Support classes or css. Example usage:
function footerStyle(value, row, index) {
          return {
            css: { "font-weight": "bold" }
          };
        }

Column optionsEdit on GitHub

 

 

The column options is defined in jQuery.fn.bootstrapTable.columnDefaults.

 

 

 

Name

Attribute

Type

Default

Description

radiodata-radioBooleanfalseTrue to show a radio. The radio column has fixed width.
checkboxdata-checkboxBooleanfalseTrue to show a checkbox. The checkbox column has fixed width.
fielddata-fieldStringundefinedThe column field name.
titledata-titleStringundefinedThe column title text.
titleTooltipdata-title-tooltipStringundefinedThe column title tooltip text. This option also support the title HTML attribute.
classclass / data-classStringundefinedThe column class name.
rowspanrowspan / data-rowspanNumberundefinedIndicate how many rows a cell should take up.
colspancolspan / data-colspanNumberundefinedIndicate how many columns a cell should take up.
aligndata-alignStringundefinedIndicate how to align the column data. 'left', 'right', 'center' can be used.
haligndata-halignStringundefinedIndicate how to align the table header. 'left', 'right', 'center' can be used.
faligndata-falignStringundefinedIndicate how to align the table footer. 'left', 'right', 'center' can be used.
valigndata-valignStringundefinedIndicate how to align the cell data. 'top', 'middle', 'bottom' can be used.
widthdata-widthNumber {Pixels or Percentage}undefinedThe width of column. If not defined, the width will auto expand to fit its contents. Though if the table is left responsive and sized too small this 'width' might be ignored (use min/max-width via class or such then). Also you can add '%' to your number and the bootstrapTable will use the percentage unit, otherwise, leave as number (or add 'px') to make it use pixels.
sortabledata-sortableBooleanfalseTrue to allow the column can be sorted.
orderdata-orderString'asc'The default sort order, can only be 'asc' or 'desc'.
visibledata-visibleBooleantrueFalse to hide the columns item.
cardVisibledata-card-visibleBooleantrueFalse to hide the columns item in card view state.
switchabledata-switchableBooleantrueFalse to disable the switchable of columns item.
clickToSelectdata-click-to-selectBooleantrueTrue to select checkbox or radio when the column is clicked.
formatterdata-formatterFunctionundefinedThe context (this) is the column Object. 
The cell formatter function, take three parameters: 
value: the field value. 
row: the row record data.
index: the row index.
footerFormatterdata-footer-formatterFunctionundefinedThe context (this) is the column Object. 
The function, take one parameter: 
data: Array of all the data rows. 
the function should return a string with the text to show in the footer cell.
eventsdata-eventsObjectundefinedThe cell events listener when you use formatter function, take four parameters: 
event: the jQuery event. 
value: the field value. 
row: the row record data.
index: the row index. 
Example code: <th .. data-events="operateEvent"> var operateEvents = {'click .like': function (e, value, row, index) {}};
sorterdata-sorterFunctionundefinedThe custom field sort function that used to do local sorting, take two parameters: 
a: the first field value.
b: the second field value.
sortNamedata-sort-nameStringundefinedProvide a customizable sort-name, not the default sort-name in the header, or the field name of the column. For example, a column might display the value of fieldName of "html" such as "<b><span style="color:red">abc</span></b>", but a fieldName to sort is "content" with the value of "abc".
cellStyledata-cell-styleFunctionundefinedThe cell style formatter function, take three parameters: 
value: the field value.
row: the row record data.
index: the row index.
field: the row field.
Support classes or css. Example usage:
function cellStyle(value, row, index, field) {
  return {
    classes: 'text-nowrap another-class',
    css: {"color": "blue", "font-size": "50px"}
  };
}
searchabledata-searchableBooleantrueTrue to search data for this column.
searchFormatterdata-search-formatterBooleantrueTrue to search use formated data.

EventsEdit on GitHub

 

 

To use event syntax:

Copy

$('#table').bootstrapTable({
    onEventName: function (arg1, arg2, ...) {
        // ...
    }
});

$('#table').on('event-name.bs.table', function (e, arg1, arg2, ...) {
    // ...
});

 

 

 

Option Event

jQuery Event

Parameter

Description

onAllall.bs.tablename, argsFires when all events trigger, the parameters contain: 
name: the event name, 
args: the event data.
onClickRowclick-row.bs.tablerow, $element, fieldFires when user click a row, the parameters contain: 
row: the record corresponding to the clicked row, 
$element: the tr element, 
field: the field name corresponding to the clicked cell.
onDblClickRowdbl-click-row.bs.tablerow, $element, fieldFires when user double click a row, the parameters contain: 
row: the record corresponding to the clicked row, 
$element: the tr element, 
field: the field name corresponding to the clicked cell.
onClickCellclick-cell.bs.tablefield, value, row, $elementFires when user click a cell, the parameters contain: 
field: the field name corresponding to the clicked cell, 
value: the data value corresponding to the clicked cell, 
row: the record corresponding to the clicked row, 
$element: the td element.
onDblClickCelldbl-click-cell.bs.tablefield, value, row, $elementFires when user double click a cell, the parameters contain: 
field: the field name corresponding to the clicked cell, 
value: the data value corresponding to the clicked cell, 
row: the record corresponding to the clicked row, 
$element: the td element.
onSortsort.bs.tablename, orderFires when user sort a column, the parameters contain: 
name: the sort column field name
order: the sort column order.
onCheckcheck.bs.tablerow, $elementFires when user check a row, the parameters contain: 
row: the record corresponding to the clicked row. $element: the DOM element checked.
onUncheckuncheck.bs.tablerow, $elementFires when user uncheck a row, the parameters contain: 
row: the record corresponding to the clicked row. $element: the DOM element unchecked.
onCheckAllcheck-all.bs.tablerowsFires when user check all rows, the parameters contain: 
rows: array of records corresponding to newly checked rows.
onUncheckAlluncheck-all.bs.tablerowsFires when user uncheck all rows, the parameters contain: 
rows: array of records corresponding to previously checked rows.
onCheckSomecheck-some.bs.tablerowsFires when user check some rows, the parameters contain: 
rows: array of records corresponding to previously checked rows.
onUncheckSomeuncheck-some.bs.tablerowsFires when user uncheck some rows, the parameters contain: 
rows: array of records corresponding to previously checked rows.
onLoadSuccessload-success.bs.tabledataFires when remote data is loaded successfully.
onLoadErrorload-error.bs.tablestatus, resFires when some errors occur to load remote data.
onColumnSwitchcolumn-switch.bs.tablefield, checkedFires when switch the column visible.
onColumnSearchcolumn-search.bs.tablefield, textFires when search by column.
onPageChangepage-change.bs.tablenumber, sizeFires when change the page number or page size.
onSearchsearch.bs.tabletextFires when search the table.
onToggletoggle.bs.tablecardViewFires when toggle the view of table.
onPreBodypre-body.bs.tabledataFires before the table body is rendered
onPostBodypost-body.bs.tabledataFires after the table body is rendered and available in the DOM
onPostHeaderpost-header.bs.tablenoneFires after the table header is rendered and availble in the DOM
onExpandRowexpand-row.bs.tableindex, row, $detailFires when click the detail icon to expand the detail view.
onCollapseRowcollapse-row.bs.tableindex, rowFires when click the detail icon to collapse the detail view.
onRefreshOptionsrefresh-options.bs.tableoptionsFires after refresh the options and before destroy and init the table
onResetViewreset-view.bs.table Fires when reset view of the table.
onRefreshrefresh.bs.tableparamsFires after the click the refresh button.

MethodsEdit on GitHub

 

 

The calling method syntax: $('#table').bootstrapTable('method', parameter);.

 

 

 

Name

Parameter

Description

Example

getOptionsnoneReturn the options object. 
getSelectionsnoneReturn selected rows, when no record selected, an empty array will return. 
getAllSelectionsnoneReturn all selected rows contain search or filter, when no record selected, an empty array will return. 
showAllColumnsnoneShow All the columns. 
hideAllColumnsnoneHide All the columns. 
getDatauseCurrentPageGet the loaded data of table at the moment that this method is called. If you set the useCurrentPage to true the method will return the data in the current page. 
getRowByUniqueIdidGet data from table, the row that contains the id passed by parameter. 
loaddataLoad the data to table, the old rows will be removed. 
appenddataAppend the data to table. 
prependdataPrepend the data to table. 
removeparamsRemove data from table, the params contains two properties: 
field: the field name of remove rows. 
values: the array of values for rows which should be removed.
 
removeAll-Remove all data from table. 
removeByUniqueIdidRemove data from table, the row that contains the id passed by parameter. 
insertRowparamsInsert a new row, the param contains following properties:
index: the row index to insert into.
row: the row data.
updateRowparamsUpdate the specified row(s), each param contains following properties: 
index: the row index to be updated. 
row: the new row data.
updateByUniqueIdparamsUpdate the specified row(s), each param contains following properties: 
id: a row id where the id should be the uniqueid field assigned to the table. 
row: the new row data.
showRowparamsShow the specified row. The param must contain at least one of the following properties: index: the row index. uniqueId: the value of the uniqueId for that row.
hideRowparamsHide the specified row. The param must contain at least one of the following properties: index: the row index. uniqueId: the value of the uniqueId for that row.
getRowsHiddenbooleanGet all rows hidden and if you pass the show parameter true the rows will be shown again, otherwise, the method only will return the rows hidden.
mergeCellsoptionsMerge some cells to one cell, the options contains following properties: 
index: the row index. 
field: the field name.
rowspan: the rowspan count to be merged. 
colspan: the colspan count to be merged.
updateCellparamsUpdate one cell, the params contains following properties: 
index: the row index. 
field: the field name.
value: the new field value. 
To disable table re-initialization you can set {reinit: false}
refreshparamsRefresh the remote server data, you can set {silent: true} to refresh the data silently, and set {url: newUrl} to change the url. To supply query params specific to this request, set {query: {foo: 'bar'}}
refreshOptionsoptionsRefresh the options
resetSearchtextSet the search text
showLoadingnoneShow loading status.
hideLoadingnoneHide loading status.
checkAllnoneCheck all current page rows.
uncheckAllnoneUncheck all current page rows.
checkInvertnoneInvert check of current page rows. Triggers onCheckSome and onUncheckSome events.
checkindexCheck a row, the row index start with 0.
uncheckindexUncheck a row, the row index start with 0.
checkByparamsCheck a row by array of values, the params contains:
field: name of the field used to find records
values: array of values for rows to check
Example: 
$("#table").bootstrapTable("checkBy", {field:"field_name", values:["value1","value2","value3"]})
uncheckByparamsUncheck a row by array of values, the params contains:
field: name of the field used to find records
values: array of values for rows to uncheck
Example: 
$("#table").bootstrapTable("uncheckBy", {field:"field_name", values:["value1","value2","value3"]})
resetViewparamsReset the bootstrap table view, for example reset the table height.
resetWidthnoneResizes header and footer to fit current columns width
destroynoneDestroy the bootstrap table.
showColumnfieldShow the specified column.
hideColumnfieldHide the specified column.
getHiddenColumns-Get hidden columns.
getVisibleColumns-Get visible columns.
scrollTovalueScroll to the number value position, the unit is 'px', set 'bottom' means scroll to the bottom.
getScrollPositionnoneGet the current scroll position, the unit is 'px'.
filterByparams(Can use only in client-side) Filter data in table, e.g. you can filter {age: 10}to show the data only age is equal to 10. You can also filter with an array of values, as in: {age: 10, hairColor: ["blue", "red", "green"]} to find data where age is equal to 10 and hairColor is either blue, red, or green.
selectPagepageGo to the a specified page.
prevPagenoneGo to previous page.
nextPagenoneGo to next page.
togglePaginationnoneToggle the pagination option.
toggleViewnoneToggle the card/table view.
expandRowindexExpand the row that has the index passed by parameter if the detail view option is set to True.
collapseRowindexCollapse the row that has the index passed by parameter if the detail view option is set to True.
expandAllRowsis subtableExpand all rows if the detail view option is set to True.
collapseAllRowsis subtableCollapse all rows if the detail view option is set to True.

LocalizationsEdit on GitHub

 

 

 

 

 

Name

Parameter

Default

formatLoadingMessage-'Loading, please wait…'
formatRecordsPerPagepageNumber'%s records per page'
formatShowingRowspageFrom, pageTo, totalRows'Showing %s to %s of %s rows'
formatDetailPaginationtotalRows'Showing %s rows'
formatSearch-'Search'
formatNoMatches-'No matching records found'
formatRefresh-'Refresh'
formatToggle-'Toggle'
formatColumns-'Columns'
formatAllRows-'All'

 

 

PS:

We can import all locale files what you need:

Copy

<script src="bootstrap-table-en-US.js"></script>
<script src="bootstrap-table-zh-CN.js"></script>
...

And then use JavaScript to switch locale:

Copy

$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['en-US']);
// $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
// ...

Or use data attributes to set locale for table:

Copy

<table data-toggle="table" data-locale="en-US">
</table>

Or use JavaScript to set locale for table:

Copy

$('table').bootstrapTable({locale:'en-US'});
  •  

转载于:https://my.oschina.net/Cosco/blog/820296

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值