加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Bootstrap table的使用方法

发布时间:2020-12-18 00:47:57 所属栏目:安全 来源:网络整理
导读:Jquery中的一些东西学习一下子,补充完善一下,毕竟有些时候没有使用到这个方式很有用,在使用bootstrap table的时候,选择当前已经选择的节点的事件中的ID的值 当前rows中有很多的数据,但是我只需要id这一个值,这个时候进行操作就非常的简单了。 2.我的后

Jquery中的一些东西学习一下子,补充完善一下,毕竟有些时候没有使用到 这个方式很有用,在使用bootstrap table的时候,选择当前已经选择的节点的事件中的ID的值 当前rows中有很多的数据,但是我只需要id这一个值,这个时候进行操作就非常的简单了。

2.我的后台呢,是使用SpringMVC进行写的,期间呢也是遇到了很多的问题,进行分页处理的时候 使用了

离线查询

,但是呢,我使用的是execute()这个方法,传入的session为代理类的数据,不能再下面这个方法中进行转换 导致错误了,我还百度了很久,最后才发现是这个问题导致的

Criteria,* to actually run the query. */ public Criteria getExecutableCriteria(Session session) { impl.setSession( ( SessionImplementor ) session ); return impl; }

后台呢,我返回的数据和格式不是按照BootStrap中的格式有点差别吧,反正就是不一样

{
"userName": "333","userType": 333,"password": "333","id": 11,"indexcode": "333"
},{
"userName": "3","id": 5,"indexcode": "33333"
}
.......
],"total": 17,"totalPage": 2,"page": 0,"hasPreviousPage": true,"hasNextPage": true,"lastPage": false,"firstPage": false
}
}

主要是这里我是用了统一的返回接口 ActionResult,这样比较方便书写格式,统一后端

private boolean success;

private String message;

private Object data;

public ActionResult(){
}

public ActionResult(boolean success){
this(success,null,null);
}

............

}

来看看前端的效果吧

前端的页面

//什么公用的bootstrapt ,JQuery啊之类的引用放进去处理了

比较重要的JS代码的说明

下面的配置文件和一些事件的重写呢,你可以查看文档,或者自己去看看你源码 这里你可以进行重写哦~~ ,extentd进行重新的覆盖!

<div class="jb51code">
<pre class="brush:js;">
BootstrapTable.DEFAULTS = {
classes: 'table table-hover',locale: undefined,height: undefined,undefinedText: '-',sortName: undefined,sortOrder: 'asc',sortStable: false,striped: false,columns: [[]],data: [],dataField: 'rows',method: 'get',url: undefined,ajax: undefined,cache: true,contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
dataType: 'json',ajaxOptions: {},queryParams: function (params) {//这个是设置查询时候的参数,我直接在源码中修改过,不喜欢offetset 我后台用的 是pageNo. 这样处理就比较的满足我的要求,其实也可以在后台改,麻烦!
return params;
},queryParamsType: 'limit',// undefined (这里是根据不同的参数,选择不同的查询的条件)
responseHandler: function (res) {//这里我查看源码的,在ajax请求成功后,发放数据之前可以对返回的数据进行处理,返回什么部分的数据,比如我的就需要进行整改的!
return res;
},pagination: false,onlyInfoPagination: false,sidePagination: 'client',// client or server
totalRows: 0,// server side need to set
pageNumber: 1,pageSize: 10,pageList: [10,25,50,100],paginationHAlign: 'right',//right,left
paginationVAlign: 'bottom',//bottom,top,both
paginationDetailHAlign: 'left',left
paginationPreText: '‹',paginationNextText: '›',search: false,searchOnEnterKey: false,strictSearch: false,searchAlign: 'right',selectItemName: 'btSelectItem',showHeader: true,showFooter: false,showColumns: false,showPaginationSwitch: false,//展示页数的选择?
showRefresh: false,showToggle: false,buttonsAlign: 'right',smartDisplay: true,escape: false,minimumCountColumns: 1,idField: undefined,uniqueId: undefined,cardView: false,detailView: false,detailFormatter: function (index,row) {
return '';
},trimOnSearch: true,clickToSelect: false,singleSelect: false,toolbar: undefined,toolbarAlign: 'left',checkboxHeader: true,sortable: true,silentSort: true,maintainSelected: false,searchTimeOut: 500,searchText: '',iconSize: undefined,buttonsClass: 'default',iconsPrefix: 'glyphicon',// glyphicon of fa (font awesome)
icons: {
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'
},customSearch: $.noop,customSort: $.noop,rowStyle: function (row,index) {
return {};
},rowAttributes: function (row,footerStyle: function (row,onAll: function (name,args) {
return false;
},onClickCell: function (field,value,row,$element) {
return false;
},onDblClickCell: function (field,onClickRow: function (item,onDblClickRow: function (item,onSort: function (name,order) {
return false;
},onCheck: function (row) {
return false;
},onUncheck: function (row) {
return false;
},onCheckAll: function (rows) {
return false;
},onUncheckAll: function (rows) {
return false;
},onCheckSome: function (rows) {
return false;
},onUncheckSome: function (rows) {
return false;
},onLoadSuccess: function (data) {
return false;
},onLoadError: function (status) {
return false;
},onColumnSwitch: function (field,checked) {
return false;
},onPageChange: function (number,size) {
return false;
},onSearch: function (text) {
return false;
},onToggle: function (cardView) {
return false;
},onPreBody: function (data) {
return false;
},onPostBody: function () {
return false;
},onPostHeader: function () {
return false;
},onExpandRow: function (index,$detail) {
return false;
},onCollapseRow: function (index,row) {
return false;
},onRefreshOptions: function (options) {
return false;
},onRefresh: function (params) {
return false;
},onResetView: function () {
return false;
}
};

看看上面的自己也基本上晓得怎么去,书写了!其实之前我根本不敢这么玩,只不过之前实习过程中导师教过我怎么去玩,所以我才敢,我相信,我可以好好的 玩好这些东西的!

上面的 footerFormatter 和 formatter 都是对于当前列的显示进行处理的事件,文档中如下 formatter: The 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.

The 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. 都是对于当前列进行处理显示

如下就是增加了两个按钮在一个单元格中

也可以在这里就增加事件的处理

官方中文档说的处理事件可以像下面这里处理

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

处理系统中存在的事件的处理,文档中有说

$('#table').on('event-name.bs.table',function (e,arg1,...) {
// ...
});
//这个名字文档中很多!
onAll all.bs.table
name,args
Fires when all events trigger,the parameters contain:
name: the event name,args: the event data.

处理一些方法,比如当前选择了多少行,全选等等

//1 当前选择选的框框的id
getSelections none Return selected rows,when no record selected,an empty array will return.

//2.全选
getAllSelections none Return all selected rows contain search or filter,an empty array will return.
$table.on('all.bs.table',name,args) {
console.log(name,args);
});
//3.删除 前台的数据,不需要从后台重新加载
remove params Remove 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.

.....很多很多的东西! 一个删除的按钮,删除所有的选择的事件!是不是很好呢!

如果大家还想深入学习,可以点击进行学习,再为大家附两个精彩的专题:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读