1 回答
TA贡献1772条经验 获得超8个赞
经过几个小时的努力,我发现当初始化数据表时,应该直接从下拉列表中获取传递的数据,而不是将变化的值分配给变量并传递该数据。
<script type="text/javascript">
//Initially gets the selected value of dropdown
var status= $("#orderStatus option:selected").text(); //This is unnecessary.
//DataTable Initialization
$(document).ready(function() {
var tableone = $('#example').DataTable( {
"processing": true,
"serverSide": true,
"paging" : true,
"searching" : true,
"sDom": 'rtip',
"iDisplayLength" : 100,
"processData": false,
"ajax": {
url :"fetch.php",
type : "POST",
//It's changed here
data : function(data){
var status = $('#orderStatus').val();
data.orderStatus = status;
}
}
} );
//Search field
$('#search').keyup(function(){
tableone.search($(this).val()).column(0).draw() ;
});
//Then Redraw the datatable when the dropdown is selected
$('#orderStatus').change(function(){
tableone.draw();
});
});
并在服务器端接收发布的下拉列表
$orderStatus = $_POST['orderStatus'];
参考:https ://makitweb.com/how-to-add-custom-filter-in-datatable-ajax-and-php/?unapproved=13009&moderation-hash=c02720a3cdf60b2886fed5a45824b850#comment-13009
添加回答
举报