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);

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。