我的代码如下,
$(document).ready(function () {
var filterDays = $("#countRecordsDay").val();
dTable = $('#topcustomer_order').dataTable({
bStateSave: true,
responsive: false,
bJQueryUI: false,
bProcessing: true,
bServerSide: true,
bFilter: false,
bLengthChange: false,
"bAutoWidth": false,
//multipleSelection: true,
iDisplayLength: 10,
sAjaxSource: CustomerOrderAjaxSource,
dom: "<'row'<'col-sm-2'l><'col-sm-10'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-12 text-right fullshowignentry'i><'col-sm-12'p>>",
fnServerParams: function (aoData) {
aoData.push({"name": "days", "value": filterDays});
},
aoColumns: [
{"sName": "Id"},
{"sName": "CustomerName"},
{"sName": "Orders"},
],
"aaSorting": [[0, 'desc']],
sPaginationType: "full_numbers"});
$('#countRecordsDay').change(function () {
dTable.api().ajax.reload();
});
重新加载数据表但没有得到参数新值的值, 请任何人帮我解决一下吗?
答案 0 :(得分:1)
这是因为您在$(document).ready
中分配参数值,即页面加载时。过滤数据表时不会调用此代码,因此filterDays
始终是默认值。
修复就是这样:
fnServerParams: function (aoData) {
aoData.push({"name": "days", "value": $("#countRecordsDay").val()});
},
这样,参数始终是当前选定的值。