DataTables.js插入数据的两种方式
一:采用数组的方式插入值
var tableData = []; var i = 0; var idxTable = 1; $.each(data, function (i, d) { tableData.push([idxTable, d.stcd, d.stnm, d.ddz, d.ddcp, d.ckflz,d.normz,d.ttcp,d.actcp,d.z,d.w,d.inq,d.oz,d.outq,d.adjw,"","","查看"]); idxTable++; }); //所有数据添加到表格中 thGridTable.fnClearTable(false); thGridTable.fnAddData(tableData);
二:采用Json对象插入值,必须在创建的时候设置列名
//创建表格 var thGridTable = $('#' + tableName).dataTable({ "sScrollY": "320px", "bPaginate": false, "bLengthChange": false, "bScrollCollapse": false, "paging": false, "ordering": false, "bSort": false, "info": false, "bFilter": false, "bJQueryUI": false, "language": { "lengthMenu": "每页 _MENU_ 条记录", "zeroRecords": "没有找到记录", "info": "共 _TOTAL_ 条记录", "infoEmpty": "无记录", "infoFiltered": "(从 _MAX_ 条记录过滤)" }, "aoColumns": [ { "mData": "stcd" }, { "mData": "stcd" }, { "mData": "stnm" }, { "mData": "ddz" }, { "mData": "ddcp" }, { "mData": "ckflz" }, { "mData": "normz" }, { "mData": "ttcp" }, { "mData": "actcp" }, { "mData": "z" }, { "mData": "w" }, { "mData": "inq" }, { "mData": "oz" }, { "mData": "outq" }, { "mData": "adjw" }, { "mData": "ddcp" }, { "mData": "ddcp" }, { "mData": "ddcp" }, ] }); //所有数据添加到表格中 thGridTable.fnClearTable(false); thGridTable.fnAddData(data);