bootstraptable 加载完成_bootstrap table onLoadSuccess加载服务端数据成功事件

编程知识 行业动态 更新时间:2024-06-13 00:22:35

bootstrap table onLoadSuccess加载服务端数据成功事件

bootstrap table onLoadSuccess加载服务端数据成功的事件,该事件的作用是什么呢?服务端返回自己格式的数据,他大不可能为了PC端还是移动端分别适配不同的JSON格式,这时前端就需要把服务器端返回的数据转换成自己需要的JSON格式数据。而bootstrap table 在绑定数据渲染之前回回调onLoadSuccess事件,给你要机会去处理服务端返回的数据格式。该事件还是非常有用的。

onLoadSuccess事件

服务器端返回数据成功的事件,返回参数如下。

参数名称说明

data服务器端返回的数据格式,如[{id:1},{id:2}]

绑定onLoadSuccess事件方法一$('#table').bootstrapTable({

columns: columns, //列对象

data: data, //要显示的数据对象

onLoadSuccess: function (data) {

alert(JSON.stringify(data));

}

});

绑定onLoadSuccess事件方法二$('#table').on('load-success.bs.table', function (e,data) {

alert(JSON.stringify(data));

});

完整代码

Bootstrap Table onLoadSuccess例子

.table-demo {

width: 80%;

margin: 30px auto 0px auto;

}

.fixed-table-header {

border-right: solid 1px #ddd;

border-top: solid 1px #ddd;

}

.fixed-table-header table {

border-top: solid 0px #ddd !important;

margin-top:-1px;

}

//设置需要显示的列

var columns = [{

field: 'Id',

title: '编号'

}, {

field: 'ProductName',

title: '名称'

}, {

field: 'StockNum',

title: '库存'

}];

//bootstrap table初始化数据

$('#table').bootstrapTable({

columns: columns,

classes: "table table-bordered table-striped table-sm ", //设置表格样式

height:400,

//******服务器端分页设置****

url: "/package/bootstrap-table-1.14.1/data.json", //服务器返回数据的网址

method: 'GET', //数据请求方式

sidePagination:'server',

search:true, //******开启搜索框****//

searchOnEnterKey:false, //******回车后执行搜索****//

pagination:true,

pageNumber:1,

pageSize:2,

pageList:"[10, 20, 50, 200]",

paginationHAlign:"left",

paginationDetailHAlign:"right",

//******服务器端分页设置****

onLoadSuccess:function(data)

{

alert(JSON.stringify(data));

}

});

更多推荐

bootstraptable 加载完成_bootstrap table onLoadSuccess加载服务端数据成功事件

本文发布于:2023-04-02 19:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/b5041087184c3323834471aec5242002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   服务端   事件   数据   bootstraptable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!