BootStrap数据表格实例代码
作者:Beauty_魅影 时间:2024-05-09 14:56:15
首先初始化页面
$(function(){
$('#archives-table').bootstrapTable({
url: "/coinSend/list",//数据源
dataField: "rows",//服务端返回数据键值 就是说记录放的键值是rows,分页时使用总记录数的键值为total
search: true,//是否搜索
cache: false,
striped: true,
pagination: true,//是否分页
sortable: true, //是否启用排序
sortOrder: "asc", //排序方式
//pageNumber:1,
pageSize: 10,//单页记录数
pageList: [5, 10, 20, 50],//分页步进值
sidePagination: "server",//服务端分页
contentType: "application/json",//请求数据内容格式 默认是 application/json 自己根据格式自行服务端处理
dataType: "json",//期待返回数据类型
method: "post",//请求方式
searchAlign: "left",//查询框对齐方式
silent: true,
queryParamsType: "limit",//查询参数组织方式
queryParams: function getParams(params) {
var param = {
pageNum: params.pageNumber,
pageSize: params.pageSize,
realName : params.search
};
return param;
},
responseHandler: function(res) {
return {
"total": res.total,//总页数
"rows": res.rows //数据
};
},
searchOnEnterKey: false,//回车搜索
showRefresh: true,//刷新按钮
showColumns: true,//列选择按钮
buttonsAlign: "left",//按钮对齐方式
toolbar: "#userToolbarsendCoin",//指定工具栏
toolbarAlign: "right",//工具栏对齐方式
columns: [
/*{
title: "全选",
field: "select",
checkbox: true,
width: 20,//宽度
align: "center",//水平
valign: "middle"//垂直
},*/
{
title: "ID",//标题
field: "id",//键名
sortable: true,//是否可排序
order: "desc"//默认排序方式
},
{
field: "userInfo.userName",
title: "用户名",
sortable: true,
titleTooltip: "this is name"
}/*,
{
field: "userInfo.id",
title: "userInfo.id",
}*/,
{
field: "userInfo.realName",
title: "真实姓名",
sortable: true,
},
{
field: "userInfo.department",
title: "所属部门",
sortable: true,
},{
field: "coinName",
title: "类型",
sortable: true,
},
{
field: "amount",
title: "数量",
sortable: true,
sorter:numSort
},
{
field: "validDateStart",
title: "有效期起",
sortable: true,
//——修改——获取日期列的值进行转换
formatter: function (value, row, index) {
var time = new Date(value);
var y = time.getFullYear();//年
var m = time.getMonth() + 1;//月
var d = time.getDate();//日
return y+"-"+m+"-"+d
}
},
{
field: "validDateEnd",
title: "有效期止",
sortable: true,
//——修改——获取日期列的值进行转换
formatter: function (value, row, index) {
var time = new Date(value);
var y = time.getFullYear();//年
var m = time.getMonth() + 1;//月
var d = time.getDate();//日
return y+"-"+m+"-"+d}
}
,
{
field: "userInfo.id",
title: "操作列",
formatter:function(value, row, rowIndex){
var userId =row.userInfo.id;
var amount =row.amount;
var validDateStart =row.validDateStart;
var validDateEnd =row.validDateEnd;
var realName =row.userInfo.realName;
console.log(userId);
console.log(realName);
console.log(amount);console.log(validDateStart);console.log(validDateEnd);
if(userId!=null){
return' '+'<a class="btn btn-info" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="sendCoin(\''+userId+'\',\''+realName+'\',\''+row.id+'\');"> <i class="icon-edit icon-white"></i>分配</a>' +' '/*+
'<a class="btn btn-info" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="editTw(\''+userId+'\',\''+amount+'\',\''+realName+'\',\''+validDateEnd+'\',\''+row.id+'\');"> <i class="icon-edit icon-white"></i>编辑</a>'*/;
}else{
return '<a class="btn btn-info" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="sendCoin(\''+userId+'\');"> <i class="icon-edit icon-white"></i>分配</a>';
}
}
}
],
onClickRow: function(row, $element) {
//$element是当前tr的jquery对象
$element.css("background-color", "white");
/*alert(row.id);
id = row.id;*/
},//单击row事件
locale: "zh-CN",//中文支持,
detailView: false, //是否显示详情折叠
detailFormatter: function(index, row, element) {
var html = '';
$.each(row, function(key, val){
html += "<p>" + key + ":" + val + "</p>"
});
return html;
}
})
/*$('#archives-table').bootstrapTable('hideColumn', 'userInfo.id');*/
/*$("#searchBtn").click(function() {
var realName = $("#realName").val();
$.ajax({
type: "post",
url: "/coinSend/list",
data: {param : param},
dataType:"json",
success : function(json) {
$("#archives-table").bootstrapTable('load', json);//主要是要这种写法
}
});
});*/
})
请求后台controller,动态获取数据
表格可以加一个手风琴样式
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>员工列表</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="ibox float-e-margins">
<table id="archives-table" class="table table-hover">
</table>
</div>
</div>
</div>
总结
以上所述是小编给大家介绍的BootStrap数据表格实例代码网站的支持!
来源:http://blog.csdn.net/wo8451401/article/details/77964354
标签:bootstrap,数据,表格
0
投稿
猜你喜欢
Python ttkbootstrap 制作账户注册信息界面的案例代码
2021-02-10 04:05:11
Mootools 1.2教程(2)——DOM选择器
2008-11-13 12:46:00
MySQL 与 Elasticsearch 数据不对称问题解决办法
2024-01-23 13:43:57
使用webpack-dev-server处理跨域请求的方法
2024-04-29 13:44:19
Python中最大最小赋值小技巧(分享)
2021-08-26 06:07:44
Python中创建对象列表的实现示例
2023-08-15 07:20:35
Python区块链客户端类开发教程
2023-06-18 03:05:51
FCKeditor编辑器添加图片上传功能及图片路径问题解决方法
2022-12-15 01:07:10
数据库触发器(Trigger)的一点使用心得
2024-01-28 14:21:29
解决python中画图时x,y轴名称出现中文乱码的问题
2023-08-04 09:00:23
详解解决Python memory error的问题(四种解决方案)
2021-03-11 14:59:11
细化解析:MySQL 服务器究竟有多稳定?
2009-01-14 11:55:00
python爬取豆瓣评论制作词云代码
2023-03-14 04:31:40
Python OpenGL绘制一场烟花盛会
2021-02-08 06:12:44
Win10下为VSCode配置LaTex编辑器的方法
2023-08-27 17:20:07
Python super()函数使用及多重继承
2022-10-06 19:21:37
如何优化SQL语句的心得浅谈
2024-01-24 00:39:09
Python中IP地址处理IPy模块的方法
2023-05-19 05:21:25
Mootools 1.2教程(21)——类(二)
2008-12-28 20:58:00
PyCharm搭建Spark开发环境的实现步骤
2022-05-21 04:21:17