BootstrapTable使用教程

本文详细介绍了Bootstrap Table的各种配置选项,包括客户端分页、服务端分页、响应处理程序、多选功能、列配置、数据格式化、分页样式等。通过这些配置,可以实现表格数据的灵活展示和交互,提升用户体验。
摘要由CSDN通过智能技术生成

1. 客户端分页和服务端分页

sidePagination

  • 属性: data-side-pagination
  • 类型: String
  • 细节:
    定义表的侧面分页,只能是 ‘client’ 或 'server'。使用 'server' 端需要设置 'url''ajax' 选项。
    请注意,所需的服务器响应格式不同,具体取决于 'sidePagination' 选项设置为 'client' 还是 'server'。请参见以下示例:
    使用客户端分页
    使用服务端分页
  • 默认: 'client'
  • 例子: 客户端分页服务器端分页

2. 表分页

pagination

  • 属性: data-pagination
  • 类型: Boolean
  • 细节:
    设置为true可在表格底部显示分页工具栏。
  • 默认: false
  • 例子: 表分页

3. 响应处理程序

responseHandler

  • 属性: data-response-handler
  • 类型: Function
  • 细节:
    在加载远程数据之前,处理程序响应数据格式,参数对象包含:
    res: 响应数据。
    jqXHR: jqXHR对象,它是XMLHTTPRequest对象的超集。有关更多信息,请参阅jqXHR类型
  • 默认: function(res) { return res }
  • 例子: 响应处理程序

4. clickToSelect

Attribute: data-click-to-select

Type: Boolean

Detail:

Set true to select checkbox or radiobox when clicking rows.

Default: false

Example: Click To Select

5. columns

Attribute: -

Type: Array

Detail:

The table columns config object, see column properties for more details.

Default: []

Example: Table Columns

6. contentType

Attribute: data-content-type

Type: String

Detail:

The contentType of request remote data, for example: application/x-www-form-urlencoded.

Default: ‘application/json’

Example: Content Type

7. dataField

Attribute: data-data-field

Type: String

Detail:

Key in incoming json containing ‘rows’ data list.

Default: ‘rows’

Example: Total/Data Field

8. dataType

Attribute: data-data-type

Type: String

Detail:

The type of data that you are expecting back from the server.

Default: ‘json’

Example: Data Type

9. detailView

Attribute: data-detail-view

Type: Boolean

Detail:

Set true to show detail view table.

Default: false

Example: Detail View

10. detailFormatter

Attribute: data-detail-formatter

Type: Function

Detail:

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.

Default: function(index, row, element) { return ‘’ }

Example: Detail View

11. escape

Attribute: data-escape

Type: Boolean

Detail:

Escapes a string for insertion into HTML, replacing &, <, >, “, `, and ‘ characters.

Default: false

Example: Table Escape

12. footerField

Attribute: data-footer-field

Type: String

Detail:

Defines the key of the footer Object (From data array or server response json). The footer Object can be used to set/define footer colspans and/or the value of the footer.

Copy
{
“rows”: [
{
“id”: 0,
“name”: “Item 0”,
“price”: “$0”,
“amount”: 3
}
],
“footer”: {
“id”: “footer id”,
“_id_colspan”: 2,
“name”: “footer name”
}
}

Default: footerField

Example: Footer Field

13. footerStyle

Attribute: data-footer-style

Type: Function

Detail:

The footer style formatter function, takes one parameter:

column: the column object.
Support classes or css. Example usage:

function footerStyle(column) {
    return {
      css: { 'font-weight': 'normal' },
      classes: 'my-class'
    }
  }

Default: {}

Example: Footer Style

14. headerStyle

Attribute: data-header-style

Type: Function

Detail:

The header style formatter function, takes one parameter:

column: the column object.
Support classes or css. Example usage:

  function headerStyle(column) {
    return {
      css: { 'font-weight': 'normal' },
      classes: 'my-class'
    }
  }

Default: {}

Example: Header Style

15. height

Attribute: data-height

Type: Number

Detail:

The height of table, enable fixed header of table.

Default: undefined

Example: Table Height

16. idField

Attribute: data-id-field

Type: String

Detail:

Indicate which field will be used as checkbox/radiobox value, its the counterpart to selectItemName.

Default: undefined

Example: Id Field

17. selectItemName

Attribute: data-select-item-name

Type: String

Detail:

The name of radio or checkbox input.

Default: ‘btSelectItem’

Example: Id Field

18. ignoreClickToSelectOn

Attribute: data-ignore-click-to-select-on

Type: Function

Detail:

Set the ignore elements clickToSelect on. Takes one parameter:

element: the element clicked on.
Return true if the click should be ignored, false if the click should cause the row to be selected. This option is only relevant if clickToSelect is true.

Default: { return [‘A’, ‘BUTTON’].includes(tagName) }

Example: Ignore Click To Select On

19. loadingFontSize

Attribute: data-loading-font-size

Type: String

Detail:

To define the font size of the loading text, the default value is ‘auto’, it will be calculated automatically according to the table width, between 12px and 32px.

Default: ‘auto’

Example: Loading Font Size

20. locale

Attribute: data-locale

Type: String

Detail:

Sets the locale to use (i.e. ‘zh-CN’). Locale files must be pre-loaded. Allows for fallback locales, if loaded, in the following order:

First tries for the locale as specified,
Then tries the locale with ‘_’ translated to ‘-‘ and the region code upper cased,
Then tries the short locale code (i.e. ‘zh’ instead of ‘zh-CN’),
And finally will use the last locale file loaded (or the default locale if no locales loaded).
If left undefined or an empty string, use the last locale loaded (or ‘en-US’ if no locale files loaded).

Default: undefined

Example: Table Locale

21. method

Attribute: data-method

Type: String

Detail:

The method type to request remote data.

Default: ‘get’

Example: Table Method

22. minimumCountColumns

Attribute: data-minimum-count-columns

Type: Number

Detail:

The minimum number of columns to hide from the columns drop down list.

Default: 1

Example: Minimum Count Columns

23. 多行选择

multipleSelectRow
Attribute: data-multiple-select-row

Type: Boolean

Detail:

Set true to enable the multiple selection row. Can use the ctrl+click to select one row or use shift+click to select a range of rows.

Default: false

Example: Multiple Select Row

24. 每页显示数量

pageList
Attribute: data-page-list

Type: Array

Detail:

When set pagination property, initialize the page size selecting list. If you include the ‘all’ or ‘unlimited’ option, all the records will be shown in your table.

Hint: If the table has lesser rows as the option(s), the options will be hidden automatically, to disable that feature you can set smartDisplay to false

Default: [10, 25, 50, 100]

Example: Page List

25. pageNumber

Attribute: data-page-number

Type: Number

Detail:

When set pagination property, initialize the page number.

Default: 1

Example: Page Number

26. pageSize

Attribute: data-page-size

Type: Number

Detail:

When set pagination property, initialize the page size.

Default: 10

Example: Page Size

27. paginationLoop

Attribute: data-pagination-loop

Type: Boolean

Detail:

Set true to enable pagination continuous loop mode.

Default: true

Example: Pagination Loop

28. paginationVAlign

Attribute: data-pagination-v-align

Type: String

Detail:

Indicate how to vertical align the pagination. ‘top’, ‘bottom’, ‘both’ (put the pagination on top and bottom) can be used.

Default: ‘bottom’

Example: Pagination V Align

29. queryParams

Attribute: data-query-params

Type: Function

Detail:

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.

Default: function(params) { return params }

Example: Query Params

30. queryParamsType

Attribute: data-query-params-type

Type: String

Detail:

Set ‘limit’ to send query params with RESTFul type.

Default: ‘limit’

Example: Query Params Type

31. rememberOrder

Attribute: data-remember-order

Type: Boolean

Detail:

Set true to remember the order for each column.

Default: false

Example: Remember Order

32. rowAttributes

Attribute: data-row-attributes

Type: Function

Detail:

The row attribute formatter function, takes two parameters:

row: the row record data.
index: the row index.
Support all custom attributes.

Default: {}

Example: Row Attributes

33. rowStyle

Attribute: data-row-style

Type: Function

Detail:

The row style formatter function, takes two parameters:

row: the row record data.
index: the row index.
Support classes or css.

Default: {}

Example: Row Style

34. searchAccentNeutralise

Attribute: data-search-accent-neutralise

Type: Boolean

Detail:

Set to true if you want to use accent neutralise feature.

Default: false

Example: Search Accent Neutralise

35. showColumns

Attribute: data-show-columns

Type: Boolean

Detail:

Set true to show the columns drop down list. We can set the switchable column option to false to hide the columns item in the drop down list.

Default: false

Example: Basic Columns and Large Columns

36. showColumnsSearch

Attribute: data-show-columns-search

Type: Boolean

Detail:

Set true to show a search for the columns filter.

Default: false

Example: Columns Search

37. showColumnsSearch

Attribute: data-show-columns-search

Type: Boolean

Detail:

Set true to show a search for the columns filter.

Default: false

Example: Columns Search

38. showFullscreen

Attribute: data-show-fullscreen

Type: Boolean

Detail:

Set true to show the fullscreen button.

Default: false

Example: Show Fullscreen

39. showPaginationSwitch

Attribute: data-show-pagination-switch

Type: Boolean

Detail:

Set true to show the pagination switch button.

Default: false

Example: Show Pagination Switch

40. showRefresh

Attribute: data-show-refresh

Type: Boolean

Detail:

Set true to show the refresh button.

Default: false

Example: Show Refresh

41. showToggle

Attribute: data-show-toggle

Type: Boolean

Detail:

Set true to show the toggle button to toggle table / card view.

Default: false

Example: Show Toggle

42. singleSelect

Attribute: data-single-select

Type: Boolean

Detail:

Set true to allow checkbox selecting only one row.

Default: false

Example: Single Select

43. toolbar

Attribute: data-toolbar

Type: String/Node

Detail:

A jQuery selector that indicates the toolbar, for example: #toolbar, .toolbar, or a DOM node.

Default: undefined

Example: Custom Toolbar

JS组件Bootstrap Table使用方法详解 转载 2016年03月21日 15:06:09 标签: Bootstrap Table 最近客户提出需求,想将原有的管理系统,做下优化,通过手机也能很好展现,想到2个方案: a方案:保留原有的页面,新设计一套适合手机的页面,当手机访问时,进入m.zhy.com(手机页面),pc设备访问时,进入www.zhy.com(pc页面) b方案:采用bootstrap框架,替换原有页面,自动适应手机、平板、PC 设备 采用a方案,需要设计一套界面,并且要得重新写适合页面的接口,考虑到时间及成本问题,故项目采用了b方案 一、效果展示 二、BootStrap table简单介绍 bootStrap table 是一个轻量级的table插件,使用AJAX获取JSON格式的数据,其分页和数据填充很方便,支持国际化 三、使用方法 1、引入js、css [js] view plain copy <!--css样式--> <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet"> <link href="css/bootstrap/bootstrap-table.css" rel="stylesheet"> <!--js--> [removed][removed] [removed][removed] [removed][removed] [removed][removed] 2、table数据填充 bootStrap table获取数据有两种方式,一是通过table 的data-url属性指定数据源,二是通过JavaScript初始化表格时指定url来获取数据 [xhtml] view plain copy ... ... [xhtml] view plain copy $('#table').bootstrapTable({ url: 'data.json' }); 第二种方式交第一种而言在处理复杂数据时更为灵活,一般使用第二种方式来进行table数据填充。 [js] view plain copy $(function () { //1.初始化Table var oTable = new TableInit(); oTable.Init(); //2.初始化Button的点击事件 /* var oButtonInit = new ButtonInit(); oButtonInit.Init(); */ }); var TableInit = function () { var oTableInit = new Object(); //初始化Table oTableInit.Init = function () { $('#tradeList').bootstrapTable({ url: '/VenderManager/TradeList', //请求后台的URL(*) method: 'post', //请求方式(*) toolbar: '#toolbar', //工具按钮用哪个容器 striped: true, //是否显示行间隔色 cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*) pagination: true, //是否显示分页(*) sortable: false, //是否启用排序 sortOrder: "asc", //排序方式 queryParams: oTableInit.queryParams,//传递参数(*) sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*) pageNumber:1, //初始化加载第一页,默认第一页 pageSize: 50, //每页的记录行数(*) pageList: [10, 25, 50, 100], //可供选择的每页的行数(*) strictSearch: true, clickToSelect: true, //是否启用点击选中行 height: 460, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度 uniqueId: "id", //每一行的唯一标识,一般为主键列 cardView: false, //是否显示详细视图 detailView: false, //是否显示父子表 columns: [{ field: 'id', title: '序号' }, { field: 'liushuiid', title: '交易编号' }, { field: 'orderid', title: '订单号' }, { field: 'receivetime', title: '交易时间' }, { field: 'price', title: '金额' }, { field: 'coin_credit', title: '投入硬币' }, { field: 'bill_credit', title: '投入纸币' }, { field: 'changes', title: '找零' }, { field: 'tradetype', title: '交易类型' },{ field: 'goodmachineid', title: '货机号' },{ field: 'inneridname', title: '货道号' },{ field: 'goodsName', title: '商品名称' }, { field: 'changestatus', title: '支付' },{ field: 'sendstatus', title: '出货' },] }); }; //得到查询的参数 oTableInit.queryParams = function (params) { var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 limit: params.limit, //页面大小 offset: params.offset, //页码 sdate: $("#stratTime").val(), edate: $("#endTime").val(), sellerid: $("#sellerid").val(), orderid: $("#orderid").val(), CardNumber: $("#CardNumber").val(), maxrows: params.limit, pageindex:params.pageNumber, portid: $("#portid").val(), CardNumber: $("#CardNumber").val(), tradetype:$('input:radio[name="tradetype"]:checked').val(), success:$('input:radio[name="success"]:checked').val(), }; return temp; }; return oTableInit; }; field字段必须与服务器端返回的字段对应才会显示出数据。 3、后台获取数据 a、servlet获取数据 [js] view plain copy BufferedReader bufr = new BufferedReader( new InputStreamReader(request.getInputStream(),"UTF-8")); StringBuilder sBuilder = new StringBuilder(""); String temp = ""; while((temp = bufr.readLine()) != null){ sBuilder.append(temp); } bufr.close(); String json = sBuilder.toString(); JSONObject json1 = JSONObject.fromObject(json); String sdate= json1.getString("sdate");//通过此方法获取前端数据 ... b、springMvc Controller里面对应的方法获取数据 [js] view plain copy public JsonResult GetDepartment(int limit, int offset, string orderId, string SellerId,PortId,CardNumber,Success,maxrows,tradetype) { ... } 4、分页(遇到问题最多的) 使用分页,server端返回的数据必须包括rows和total,代码如下: [js] view plain copy ...gblst = SqlADO.getTradeList(sql,pageindex,maxrows); JSONArray jsonData=new JSONArray(); JSONObject jo=null; for (int i=0,len=gblst.size();i<len;i++) { TradeBean tb = gblst.get(i); if(tb==null) { continue; } jo=new JSONObject(); jo.put("id", i+1); jo.put("liushuiid", tb.getLiushuiid()); jo.put("price", String.format("%1.2f",tb.getPrice()/100.0)); jo.put("mobilephone", tb.getMobilephone()); jo.put("receivetime", ToolBox.getYMDHMS(tb.getReceivetime())); jo.put("tradetype", clsConst.TRADE_TYPE_DES[tb.getTradetype()]); jo.put("changestatus", (tb.getChangestatus()!=0)?"成功":"失败"); jo.put("sendstatus", (tb.getSendstatus()!=0)?"成功":"失败"); jo.put("bill_credit", String.format("%1.2f",tb.getBill_credit()/100.0)); jo.put("changes",String.format("%1.2f",tb.getChanges()/100.0)); jo.put("goodroadid", tb.getGoodroadid()); jo.put("SmsContent", tb.getSmsContent()); jo.put("orderid", tb.getOrderid()); jo.put("goodsName", tb.getGoodsName()); jo.put("inneridname", tb.getInneridname()); jo.put("xmlstr", tb.getXmlstr()); jsonData.add(jo); } int TotalCount=SqlADO.getTradeRowsCount(sql); JSONObject jsonObject=new JSONObject(); jsonObject.put("rows", jsonData);//JSONArray jsonObject.put("total",TotalCount);//总记录数 out.print(jsonObject.toString()); ... 5、分页界面内容介绍 前端获取分页数据,代码如下: [js] view plain copy ...oTableInit.queryParams = function (params) { var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 limit: params.limit, //第几条记录 offset: params.offset, //显示一页多少记录 sdate: $("#stratTime").val(), }; return temp; };... 后端获取分页数据,代码如下: [js] view plain copy ...int pageindex=0; int offset = ToolBox.filterInt(json1.getString("offset")); int limit = ToolBox.filterInt(json1.getString("limit")); if(offset !=0){ pageindex = offset/limit; } pageindex+= 1;//第几页... 以上就是为大家分享的Bootstrap Table使用方法,希望对大家熟练掌握Bootstrap Table使用方法有所帮助。 转自:http://www.jb51.net/article/79033.htm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值