bootstrap table 设置行背景色

阅读: 评论:0

bootstrap table 设置行背景色

bootstrap table 设置行背景色

先看一个例子:

<link href=".3.7/css/bootstrap.min.css">
<link href=".16.0/bootstrap-table.min.css">
<script src=".5.1/jquery.min.js"></script>	
<script src=".3.7/js/bootstrap.min.js"></script>
<script src=".16.0/bootstrap-table.min.js"></script>
<script src=".16.0/locale/bootstrap-table-zh-CN.min.js"></script><table id="mytab" class="table table-hover" style="word-break:break-all; word-wrap:break-all;" data-click-to-select="true" ></table><script>
$('#mytab').bootstrapTable({showRefresh: true,showColumns:true,showHeader:true,dataField : "data",rowStyle: function(row, index) {var classes = ['active', 'success', 'info', 'warning', 'danger'];if (index % 2 === 0 && index / 2 < classes.length) {return {classes: classes[index / 2]};}return {};},columns: [{field:'state',checkbox:true},{field: 'schemaId',title: 'ID',visible:false},{field: 'interfaceName',title: '接口名'},{field: 'schema',title: 'schema',formatter: function(value, row, index) {return "<a href='javascript:;' class='btn_view'  >查看</a>";},events: {'click .btn_view': function(e, value, row, index) {showSchema(row);}}},{field: 'createTime',title: '创建时间'}]
});
$(".fixed-table-body").height(420);//设置表格高度
//加载表格数据
$.ajax({url: my_url,type: "get",success:function(_data){if (_de == 'A00000') {var data = _data.data;$("#mytab").bootstrapTable('load', data);} else {alert('查询接口case列表请求出错');return;}},error:function() {alert('查询接口case列表请求出错');}
});//获取表格选中的数据
function test() {var rows = $('#mytab').bootstrapTable('getSelections');if (rows.length==1) {alert(rows[0].schemaId);}
}</script>

知识点:

1、隐藏某一列,可以使用visible:false 属性设置;

2、表格添加多选按钮,可以在columns中添加checkbox:true属性,如果要点击某个选中,可以配置data-click-to-select="true"

3、获取选中行数据:

var rows = $('#mytab').bootstrapTable('getSelections');

4、设置表格高度:$(".fixed-table-body").height(420); 这样,当表格中数据超过时会自动出现滚动条。

5、设置某行背景色:

function rowStyle(row, index) {var classes = ['active', 'success', 'info', 'warning', 'danger'];if (index % 2 === 0 && index / 2 < classes.length) {return {classes: classes[index / 2]};}return {};
}

6、表格前面的checkout禁用:

{checkbox : true,width : 50,formatter: function(value, row, index) {if(row.status === 0){//如果已经操作禁止选择return { disabled : false,}}else{return { disabled : true,}}}
},

 

本文发布于:2024-01-28 08:27:42,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17064016666106.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:背景色   bootstrap   table
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23