BootStrapTable参数方法

本文详细介绍 Bootstrap Table 的各项配置参数及其使用方法,包括表格的基本配置、列配置、事件及方法等,帮助开发者快速掌握并应用到实际项目中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

表格参数


名称标签  类型默认描述
-data-toggleString'table'不用写 JavaScript 直接启用表格。
classesdata-classesString'table table-hover'表格的类名称。默认情况下,表格是有边框的,你可以添加
'table-no-bordered' 来删除表格的边框样式。
sortClassdata-sort-classStringundefinedThe class name of the td elements which are sorted.
heightdata-heightNumberundefined定义表格的高度。
undefinedTextdata-undefined-textString'-'当数据为 undefined 时显示的字符
stripeddata-stripedBooleanfalse设置为 true 会有隔行变色效果
sortNamedata-sort-nameStringundefined定义排序列,通过url方式获取数据填写字段名,否则填写下标
sortOrderdata-sort-orderString'asc'定义排序方式 'asc' 或者 'desc'
sortStabledata-sort-stableBooleanfalse设置为 true 将获得稳定的排序,我们会添加_position属性到
 row 数据中。
iconsPrefixdata-icons-prefixString'glyphicon'定义字体库 ('Glyphicon' or 'fa' for FontAwesome),使用"fa"时需引用
FontAwesome,并且配合 icons 属性实现效果
Glyphicon 集成于Bootstrap可免费使用 参考:http://glyphicons.com/
FontAwesome 参考:http://fortawesome.github.io/
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'
}
自定义图标
columns-Array[]列配置项,详情请查看 列参数 表格.
data-Array[]加载json格式的数据
ajaxdata-ajaxFunctionundefined自定义 AJAX 方法,须实现 jQuery AJAX API
methoddata-methodString'get'服务器数据的请求方式 'get' or 'post'
urldata-urlStringundefined服务器数据的加载地址
cachedata-cacheBooleantrue设置为 true 禁用 AJAX 数据缓存
contentTypedata-content-typeString'application/json'发送到服务器的数据编码类型
dataTypedata-data-typeString'json'服务器返回的数据类型
ajaxOptionsdata-ajax-optionsObject{}提交ajax请求时的附加参数,可用参数列请查看
http://api.jquery.com/jQuery.ajax.
queryParamsdata-query-paramsFunctionfunction(params) {
return params;
}
请求服务器数据时,你可以通过重写参数的方式添加一些额外的参数,
例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
limit, offset, search, sort, order 否则, 需要包含: 
pageSize, pageNumber, searchText, sortName, sortOrder. 
返回false将会终止请求
queryParamsTypedata-query-params-typeString'limit'设置为 'limit' 则会发送符合 RESTFul 格式的参数.
responseHandlerdata-response-handlerFunctionfunction(res) {
return res;
}
加载服务器数据之前的处理程序,可以用来格式化数据。
参数:res为从服务器请求到的数据。
paginationdata-paginationBooleanfalse设置为 true 会在表格底部显示分页条
paginationLoopdata-pagination-loopBooleantrue设置为 true 启用分页条无限循环的功能。
onlyInfoPaginationdata-only-info-paginationBooleanfalse设置为 true 只显示总数据数,而不显示分页按钮。需要 pagination='True'
sidePaginationdata-side-paginationString'client'设置在哪里进行分页,可选值为 'client' 或者 'server'。设置 'server'时,
必须设置服务器数据地址(url)或者重写ajax方法
pageNumberdata-page-numberNumber1如果设置了分页,首页页码
pageSizedata-page-sizeNumber10如果设置了分页,页面数据条数
pageListdata-page-listArray[10, 25, 50, 100, All]如果设置了分页,设置可供选择的页面数据条数。设置为All 则显示所有记录。
selectItemNamedata-select-item-nameString'btSelectItem'radio or checkbox 的字段名
smartDisplaydata-smart-displayBooleantrueTrue to display pagination or card view smartly.
escapedata-escapeBooleanfalse转义HTML字符串,替换 &<>"`, 和 ' 字符.
searchdata-searchBooleanfalse是否启用搜索框
searchOnEnterKeydata-search-on-enter-keyBooleanfalse设置为 true时,按回车触发搜索方法,否则自动触发搜索方法
strictSearchdata-strict-searchBooleanfalse设置为 true启用 全匹配搜索,否则为模糊搜索
searchTextdata-search-textString''初始化搜索文字
searchTimeOutdata-search-time-outNumber500设置搜索超时时间
trimOnSearchdata-trim-on-searchBooleantrue设置为 true 将允许空字符搜索
showHeaderdata-show-headerBooleantrue是否显示列头
showFooterdata-show-footerBooleanfalse是否显示列脚
showColumnsdata-show-columnsBooleanfalse是否显示 内容列下拉框
showRefreshdata-show-refreshBooleanfalse是否显示 刷新按钮
showToggledata-show-toggleBooleanfalse是否显示 切换试图(table/card)按钮
showPaginationSwitchdata-show-pagination-switchBooleanfalse是否显示 数据条数选择框
minimumCountColumnsdata-minimum-count-columnsNumber1当列数小于此值时,将隐藏内容列下拉框。
idFielddata-id-fieldStringundefined指定主键列
uniqueIddata-unique-idStringundefinedIndicate an unique identifier for each row.
cardViewdata-card-viewBooleanfalse设置为 true将显示card视图,适用于移动设备。否则为table试图,
适用于pc
detailViewdata-detail-viewBooleanfalse设置为 true 可以显示详细页面模式。
detailFormatterdata-detail-formatterFunctionfunction(index, row) {
return '';
}
格式化详细页面模式的视图。
searchAligndata-search-alignString'right'指定 搜索框 水平方向的位置。'left' or 'right'
buttonsAligndata-buttons-alignString'right'指定 按钮 水平方向的位置。'left' or 'right'
toolbarAligndata-toolbar-alignString'left'指定 toolbar 水平方向的位置。'left' or 'right'
paginationVAligndata-pagination-v-alignString'bottom'指定 分页条 在垂直方向的位置。'top' or 'bottom' or 'bonth'
paginationHAligndata-pagination-h-alignString'right'指定 分页条 在水平方向的位置。'left' or 'right'
paginationDetailHAligndata-pagination-detail-h-alignString'left'指定 分页详细信息 在水平方向的位置。'left' or 'right'
paginationPreTextdata-pagination-pre-textString'<'指定分页条中上一页按钮的图标或文字
paginationNextTextdata-pagination-next-textString'>'指定分页条中下一页按钮的图标或文字
clickToSelectdata-click-to-selectBooleanfalse设置true 将在点击行时,自动选择rediobox 和 checkbox
singleSelectdata-single-selectBooleanfalse设置True 将禁止多选
toolbardata-toolbarStringundefined一个jQuery 选择器,指明自定义的toolbar 例如:
#toolbar, .toolbar.
checkboxHeaderdata-checkbox-headerBooleantrue设置false 将在列头隐藏check-all checkbox .
maintainSelecteddata-maintain-selectedBooleanfalse设置为 true 在点击分页按钮或搜索按钮时,将记住checkbox的选择项
sortabledata-sortableBooleantrue设置为false 将禁止所有列的排序
silentSortdata-silent-sortBooleantrue设置为 false 将在点击分页按钮时,自动记住排序项。
仅在 sidePagination设置为 server时生效.
rowStyledata-row-styleFunctionfunction(row,index) {
return class;
}
自定义行样式 参数为:
row: 行数据
index: 行下标
返回值可以为class或者css
rowAttributesdata-row-attributesFunctionfunction(row,index) {
return attributes;
}
自定义行属性 参数为:
row: 行数据
index: 行下标
返回值可以为class或者css 支持所有自定义属性
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`.}

列参数


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

NameAttributeTypeDefaultDescription
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. Also you can add '%' to your number and the bootstrapTable will use the percentage unit, otherwise, you can add or no the 'px' to your number and then the bootstrapTable will use the 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 radiobox 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 three parameters: 
event: the jQuery event. 
value: the field value. 
row: the row record data.
index: the 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.
searchabledata-searchableBooleantrueTrue to search data for this column.
searchFormatterdata-search-formatterBooleantrueTrue to search use formated data.

事件


Option 事件jQuery 事件参数描述
onAllall.bs.tablename, args所有的事件都会触发该事件,参数包括:
name:事件名,
args:事件的参数。
onClickRowclick-row.bs.tablerow, $element当用户点击某一行的时候触发,参数包括:
row:点击行的数据,
$element:tr 元素,
field:点击列的 field 名称。
onDblClickRowdbl-click-row.bs.tablerow, $element当用户双击某一行的时候触发,参数包括:
row:点击行的数据,
$element:tr 元素,
field:点击列的 field 名称。
onClickCellclick-cell.bs.tablefield, value, row, $element当用户点击某一列的时候触发,参数包括:
field:点击列的 field 名称,
value:点击列的 value 值,
row:点击列的整行数据,
$element:td 元素。
onDblClickCelldbl-click-cell.bs.tablefield, value, row, $element当用户双击某一列的时候触发,参数包括:
field:点击列的 field 名称,
value:点击列的 value 值,
row:点击列的整行数据,
$element:td 元素。
onSortsort.bs.tablename, orderFires when user sort a column, the parameters contains: 
name: the sort column field name
order: the sort column order.
onCheckcheck.bs.tablerowFires when user check a row, the parameters contains: 
row: the record corresponding to the clicked row. $element: the DOM element checked.
onUncheckuncheck.bs.tablerowFires when user uncheck a row, the parameters contains: 
row: the record corresponding to the clicked row. $element: the DOM element unchecked.
onCheckAllcheck-all.bs.tablerowsFires when user check all rows, the parameters contains: 
rows: array of records corresponding to newly checked rows.
onUncheckAlluncheck-all.bs.tablerowsFires when user uncheck all rows, the parameters contains: 
rows: array of records corresponding to previously checked rows.
onCheckSomecheck-some.bs.tablerowsFires when user check some rows, the parameters contains: 
rows: array of records corresponding to previously checked rows.
onUncheckSomeuncheck-some.bs.tablerowsFires when user uncheck some rows, the parameters contains: 
rows: array of records corresponding to previously checked rows.
onLoadSuccessload-success.bs.tabledataFires when remote data is loaded successfully.
onLoadErrorload-error.bs.tablestatusFires 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.tablenoneFires 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, $detail当点击详细图标展开详细页面的时候触发。
onCollapseRowcollapse-row.bs.tableindex, row当点击详细图片收起详细页面的时候触发。
onRefreshOptionsrefresh-options.bs.tableoptionsFires after refresh the options and before destroy and init the table.
onRefreshrefresh.bs.tableparamsFires after the click the refresh button.

方法


使用方法的语法:$('#table').bootstrapTable('method', parameter);

名称参数描述例子
getOptionsnone返回表格的 Options。getOptions
getSelectionsnone返回所选的行,当没有选择任何行的时候返回一个空数组。getSelections
getAllSelectionsnone返回所有选择的行,包括搜索过滤前的,当没有选择任何行的时候返回一个空数组。getAllSelections
getDatauseCurrentPage或者当前加载的数据。假如设置 useCurrentPage 为 true,则返回当前页的数据。getData
getRowByUniqueIdid根据 uniqueId 获取行数据。getRowByUniqueId
loaddata加载数据到表格中,旧数据会被替换。load
showAllColumnsnoneShow All the columns.showAllColumns
hideAllColumnsnoneHide All the columns.hidAllColumns
appenddata添加数据到表格在现有数据之后。append
prependdata插入数据到表格在现有数据之前。prepend
removeparams从表格中删除数据,包括两个参数: field: 需要删除的行的 field 名称。
values: 需要删除的行的值,类型为数组。
remove
removeAll-删除表格所有数据。removeAll
removeByUniqueIdid根据 uniqueId 删除指定的行。removeByUniqueId
insertRowparams插入新行,参数包括:
index: 要插入的行的 index。
row: 行的数据,Object 对象。
insertRow
updateRowparams更新指定的行,参数包括:
index: 要更新的行的 index。
row: 行的数据,Object 对象。
updateRow
showRowparams显示指定的行,参数包括:
index: 要更新的行的 index 或者 uniqueId。
isIdField: 指定 index 是否为 uniqueid。
showRow-hideRow
hideRowparams显示指定的行,参数包括:
index: 要更新的行的 index。
uniqueId: 或者要更新的行的 uniqueid。
showRow-hideRow
getRowsHiddenshowGet 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.
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.
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-获取隐藏的列。
getVisibleColumns-获取可见列。
scrollTovalue滚动到指定位置,单位为 px,设置 'bottom' 表示跳到最后。
getScrollPositionnone获取当前滚动条的位置,单位为 px。
filterByparams(只能用于 client 端)过滤表格数据, 你可以通过过滤{age: 10}来显示 age 等于 10 的数据。
selectPagepage跳到指定的页。
prevPagenone跳到上一页。
nextPagenone跳到下一页。
togglePaginationnone切换分页选项。
toggleViewnone切换 card/table 视图
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.

多语言


NameParameterDefault
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:

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

And then use JavaScript to switch locale:

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

<think>首先,用户在询问关于BootstrapTable组件中重载方法的信息。用户提到“reloadmethod”,但在提供的引用中,实际的关键词是“refresh”或“refreshOptions”。从引用中:-引用[1]展示了如何使用`refreshOptions`和`refresh`方法来改变BootstrapTable的选项或数据源。```javascript$("#tablelist").bootstrapTable('refreshOptions',{sidePagination:'client'});$("#tablelist").bootstrapTable('refresh',{url:"...",query:{...}});```-引用[2]和[4]提供了一些背景,但没有直接相关的重载方法示例。-引用[3]标题是“bootstrap-table重载”,用户说“BootstrapTable的使用总结”,但没有提供具体代码,只是提到行选择事件。所以,"reload"很可能指的是刷新或重载表格数据,这与"refresh"方法匹配。不是所有表格组件都直接有"reload"方法,但BootstrapTable的"refresh"方法就是用于这个目的。现在,我需要结构化我的回答:1.**系统级指令遵守**:-使用$...$为行内数学表达式(但在这个主题中,不太可能有数学;可能用于代码变量如$var,但一般用于数学)。-用$$...$$为独立公式(同样,不适用)。-LaTeX语法正确。-使用中文回答。-在回答末尾生成相关问题。-引用段落末尾添加引用标识如[^1]。2.**回答内容**:-清晰的结构:介绍方法,然后提供示例。-从引用中提取相关代码:主要从引用[1]和[3]。-参考用户的需求:"我想查找关于BootstrapTable组件中如何使用JavaScript实现重载方法的相关信息或示例代码"-提供真实可靠的示例代码。示例代码步骤:-展示如何使用`refresh`方法重载表格数据。-解释参数如url和query。-可能提到`refreshOptions`来更改选项。使用Markdown格式化代码块:```javascript//示例代码```3.**引用处理**:-引用中提到[^1],[^2],[^3],[^4]。-在我的回答中,当我提到相关概念时,添加引用。-例如,解释`refresh`方法时,引用[1]。4.**相关问题生成**:-在回答末尾,添加"相关问题:"部分。-问题需相关,如基于BootstrapTable方法、优化等。列出相关问题:1.如何更新BootstrapTable中的数据而不刷新整个页面?2.BootstrapTable中如何处理服务器端分页?3.如何结合其他插件如jstree使用BootstrapTable?现在,结构回答:1.引言:解释重载方法。2.主内容:提供示例代码和解释。3.结束:生成相关问题。用中文写。</think> ### Bootstrap Table组件中重载方法的使用指南 在 Bootstrap Table 组件中,“重载”通常指刷新表格数据或动态修改配置选项,以实现数据的重新加载。核心方法是使用 JavaScript 调用 `refresh` 或 `refreshOptions` API。这些方法允许您在不重新加载整个页面的情况下更新表格内容。以下说明基于引用内容整理,并以代码示例展示实现方式。 #### 重载方法的 JavaScript 实现 Bootstrap Table 提供了 `refresh` 方法用于重载数据源,以及 `refreshOptions` 方法用于动态更新表格配置(如分页方式)。以下是详细解释和示例代码: 1. **`refresh` 方法:重载数据源** - **功能**:重新加载表格数据,可通过 URL 或查询参数动态获取新数据。 - **语法**:`$('#tableId').bootstrapTable('refresh', options);` - `options` 是一个对象,包含 `url`(数据源地址)和 `query`(传递给后台的参数)。 - **使用场景**:当需要根据用户输入(如搜索框值)重新查询数据时使用。 - **示例代码**: ```javascript // 假设表格元素 ID 为 'tablelist' $("#tablelist").bootstrapTable('refresh', { url: "/api/data", // 重设数据来源 URL query: { username: $('#search-username').val(), // 获取输入框值作为参数 realname: $('#search-realname').val(), mobile: $('#search-mobile').val() } }); ``` - **解释**:此代码会根据输入框值(如用户名)重新查询后台数据,并刷新表格内容。参数 `query` 对象传递给服务器,后端可根据这些参数过滤结果。引用显示,`refresh` 常用于更新数据源,例如在搜索场景中[^1]。 2. **`refreshOptions` 方法:重载配置选项** - **功能**:动态修改表格的配置选项(如分页方式),然后触发表格重载。 - **语法**:`$('#tableId').bootstrapTable('refreshOptions', newOptions);` - `newOptions` 是一个对象,包含需要更新的配置键值对。 - **使用场景**:当需要切换分页模式(从服务器端分页改为客户端分页)时。 - **示例代码**: ```javascript // 将分页方式改为客户端分页,无需服务器交互 $("#tablelist").bootstrapTable('refreshOptions', { sidePagination: 'client' // 修改为客户端分页 }); // 可选:接着调用 refresh 重新加载数据 $("#tablelist").bootstrapTable('refresh'); ``` - **解释**:此方法先更新配置(如 `sidePagination`),然后通过 `refresh` 应用新配置。引用中提到,这在需要改变分页方式时非常有用[^1]。注意,单独使用 `refreshOptions` 不会自动加载数据,需与 `refresh` 配合。 #### 关键注意事项 - **方法兼容性**:Bootstrap Table 的 `refresh` 和 `refreshOptions` 是标准 API,确保使用最新版本的 Bootstrap Table 以避免兼容问题。 - **性能优化**:当表格数据量大时(如引用[4]中的异步加载需求),建议在服务器端实现分页和过滤,以减少前端加载时间。 - **错误处理**:如果数据解析出错(如引用[2]提到的空值问题),检查输入格式或使用字符串处理函数纠正解析问题。 - **行操作支持**:引用[3]强调,可通过选择事件(如行 ID)动态操作数据,例如结合 `refresh` 仅重载特定行。 #### 完整使用示例 以下是一个结合搜索功能的重载场景,用户输入搜索条件后表格实时刷新: ```html <div> <input id="search-username" type="text" placeholder="输入用户名"> <button onclick="reloadTable()">重载表格</button> <table id="tablelist" data-toggle="table" data-url="/api/data" data-side-pagination="server" <!-- 初始为服务器分页 --> data-pagination="true"> </table> </div> <script> function reloadTable() { // 动态修改分页选项 $("#tablelist").bootstrapTable('refreshOptions', { sidePagination: 'client' // 改为客户端分页以本地过滤 }); // 重载数据基于搜索框值 $("#tablelist").bootstrapTable('refresh', { url: "/api/data", query: { username: $('#search-username').val() } }); } </script> ``` - **说明**:用户点击按钮时,先切换分页模式,然后刷新数据。这体现了引用中提到的灵活重载方式[^1]。 总结来说,Bootstrap Table 的 `refresh` 和 `refreshOptions` 方法提供了高效的表格重载机制,支持动态数据更新和配置调整。合理使用时,能大幅提升用户体验。 相关问题: 1. 如何在 Bootstrap Table 中实现服务器端分页与搜索的集成? 2. Bootstrap Table 的数据重载方法与其他插件(如 jstree)结合有哪些常见问题? 3. Bootstrap Table 的性能优化技术有哪些,尤其是在大数据量场景下? [^1]: Bootstrap Table 文档和示例代码展示了 `refresh` 和 `refreshOptions` 的使用方法。 [^2]: `bootstrap-table-editable.js` 文件可能影响数据解析过程。 [^3]: 通过行选择事件实现特定数据的重载操作。 [^4]: jstree 与 Bootstrap Table 结合的异步加载方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值