2 u010345450 u010345450 于 2016.02.19 17:01 提问

jQuery的datatable更新问题

function getProvince() {
var province=document.getElementById("selProvince").value;
$('#buchongList').dataTable().fnClearTable();
$.ajax({
type: "post",
url: "/IotCloud-bugtrapper-service/rest/dynamic/listDynamicData",
datatype: "json",
data: {
"time_type":"0",
"filter_province":"10"
},
success: function (data) {
info = data.data;
table = $('#buchongList').DataTable({
"filter": [ 6, false ],
"bPaginate": true,
"pagingType": "full_numbers",
"bFilter": true,
"bLengthChange": true,
"bDestroy":true,
"bInfo": true,
"bSort": true,
"retrieve":true,
"oLanguage": {
"sZeroRecords": "没有数据",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "前一页",
"sNext": "后一页",
"sLast": "尾页"
}
},

            "columnDefs": [
                {
                "targets": [12],
                "defaultContent": "<button id='shuju' style='cursor:pointer;color:#009ACD; margin-left:20px; background-color:transparent;border:none;outline:none;'><img src='img/icon2.png'></button>" +
                "<button id='download' style='cursor:pointer;color:#009ACD; margin-left:0px; background-color:transparent;border:none;outline:none;'><img src='img/icon1.png'></button>"+
                "<button id='reset' style='cursor:pointer;color:#009ACD; margin-left:0px; background-color:transparent;border:none;outline:none;'><img src='img/icon3.png'></button>"
            },
                {"orderable":false,"targets":[3,4,5]
            }, {"targets": [ 0 ], "visible": false},
            ],
            data:info,
            columns: [
                {data: ''},
                {data: 'gatewayId'},
                {data: "trapperUnitId"},
                {data: 'trapperName'},
                {data: 'locationName'},
                {data: 'trapperAddr'},
                {data: 'temp'},
                {data: 'humidity'},
                {data: 'windSpeed'},
                {data: 'lightSource'},
                {data: 'rainfall'},
                {data: 'bugCount'}
            ]
        });

    }

})

}
要实现table更新。我先clear了表格,然后却加载不出数据了?求大神解释,谢谢。

1个回答

showbo
showbo   Ds   Rxr 2016.02.19 19:54

不要重新构造,应该是没用,用fnAddData方法循环添加数据,自己看api
http://legacy.datatables.net/ref

 // Global var for counter
var giCount = 2;

$(document).ready(function() {
  $('#example').dataTable();
} );

function fnClickAddRow() {
  $('#example').dataTable().fnAddData( [
    giCount+".1",
    giCount+".2",
    giCount+".3",
    giCount+".4" ]
  );

  giCount++;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!