用js快速动态生成bootstrap table表格数据

1.html页面

 <div class="tableArea ">
    <table class="table table-striped" id="table" data-height="600">
        <!--在此处填充表格数据-->
    </table>
 </div>
  1. js方法
<script type="text/javascript">
    var $table = $('#table');//绑定表格id
    $(function () {
        buildTable($table, 24, 24); //设置所要加载的表格列数和行数,此处为24行24列
    });

    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] = 'Row-' + i + '-' + j;
            }
            data.push(row);
        }
        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            data: data,
            search: true,
            toolbar: '.toolbar',
        });
    }

</script>

这里写图片描述

具体请参照官网:http://issues.wenzhixin.net.cn/bootstrap-table/

猜你喜欢

转载自blog.csdn.net/wbx_wlg/article/details/78748333