1:需要引用的js和css
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-table.css">
<link rel="stylesheet" href="css/bootstrap-table-fixed-columns.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-table.js"></script>
<script src="js/bootstrap-table-fixed-columns.js"></script>
2:示例展示:
<div class="container">
<h1>Fixed Columns</h1>
<div class="toolbar form-inline">
<span>Fixed Number: </span>
<input class="form-control" id="fixedNumber" type="number" value="1" min="1" max="5">
</div>
<table id="table" data-height="400" data-show-columns="true"></table>
</div>
3:填写数据:
<script>
var $table = $('#table');
$(function () {
buildTable($table, 20, 20);
$('#fixedNumber').change(function () {
buildTable($table, 20, 20);
});
});
function buildTable($el, cells, rows) {
var i, j, row,
columns = [],
data = [];
for (i = 0; i < cells; i++) {
columns.push({
field: 'field' + i,
title: 'Cell' + i,
sortable: true
});
}
for (i = 0; i < rows; i++) {
row = {};
for (j = 0; j < cells; j++) {
row['field' + j] = 'Rows-' + i + '-' + j;
}
data.push(row);
}
$el.bootstrapTable('destroy').bootstrapTable({
columns: columns,
data: data,
search: true,
toolbar: '.toolbar',
fixedColumns: true,
fixedNumber: +$('#fixedNumber').val()
});
}
</script>
4:bootstrap-table-fixed-columns.js中固定列代码:
fixedColumns: true, //是否固定
fixedNumber: 1 //固定列数
5:展示效果:上传不了视频。。。。。。
6:需要的js和css以及代码链接:
链接:https://download.csdn.net/download/weixin_42162163/19336613
总的来说这个控件很好,但还不够成熟,需要的可以借鉴,自己可以修改js和css来得到你所想要的效果。
博主也是个菜鸟,就献丑了。