1. 程式人生 > >用js快速動態生成bootstrap table表格資料

用js快速動態生成bootstrap table表格資料

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', }); }