码迷,mamicode.com
首页 > Web开发 > 详细

DataTables.js插入数据的两种方式

时间:2015-01-22 23:07:34      阅读:1163      评论:0      收藏:0      [点我收藏+]

标签:

 

一:采用数组的方式插入值 

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

 

DataTables.js插入数据的两种方式

标签:

原文地址:http://www.cnblogs.com/coolsundy/p/4242788.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!