【发布时间】:2017-06-02 15:04:32
【问题描述】:
我为我的数据表编写了以下代码,它用我的数据库中的内容填充表格,如下所示:
if (datatable != null)
datatable.destroy();
datatable = $('#tableProducts').DataTable({
"pageLength": 50,
"bLengthChange": false,
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"bSort": false,
"ajax": {
"url": "/Bulk/LoadData/",
"type": "POST",
"data": {
"username": $(".sellerInput").val(),
"drange": $(".select2").val()
},
success: function (data) {
}
},
"columns": [
{
"targets": -1,
"data": "ImageURL",
"name": "Title",
"render": function (data, type, row) {
return '<td><img src=' + data + '></td>';
},
"autoWidth": true
},
{
"data": "Sales",
"name": "QuantitySold",
"render": function (data, type, row) {
return '<td>' + data + '</td>'
},
},
{
"data": "CurrentPrice",
"name": "CurrenctPrice",
"render": function (data, type, row) {
return '<td> <b>$ ' + data + '</b></td>'
},
}
]
});
如果我不指定成功回调,这很好用。如果我这样指定成功回调(也显示在上面的代码中):
"ajax": {
"url": "/Bulk/LoadData/",
"type": "POST",
"data": {
"username": $(".sellerInput").val(),
"drange": $(".select2").val()
},
success: function (data) {
// some custom code here and + filling up datatable with data from my DB...
}
},
这里的问题是,如果我指定成功回调,然后更新我的 HTML 页面的其他部分,那么数据表不会加载数据库中的数据..
我的问题是,如果我覆盖数据表的成功回调函数以更新我的 HTML 页面的更多部分而不仅仅是数据表本身,我该如何手动指定数据表的数据源?
有人可以帮帮我吗?
【问题讨论】:
标签: javascript jquery html ajax datatables