我在CodeIgniter工作,我有一个DataTable,我想在调用ajax后过滤DT中的数据。我试图通过过滤表格来做到这一点,但它无法正常工作。
这是JS代码。
$(function () {
var tableRep= $("#tblreport").dataTable({
responsive: true, filter:true, order: [[ 1, "desc" ]],
processing: true, serverSide: true,
ajax: { "url": baseurl+"reports/Report/dataTable", "type": "POST" },
columns:
[
{data:"idReport",},
{data:"date"},
{data:"customer"},
{data:"status",visible:false},
{data:null,searchable:false,orderable: false,width:"120px", render: function (row)
{ if (row.status == "wait") {return '<a class="glyphicon glyphicon-search" data-toggle="modal" data-target="#report">Asign</a>'; }
else if (row.status == "process") {return '<a data-toggle="modal" data-target="#report">Edit</a>';} else return '';} }
],
columnDefs:
[
{ responsivePriority: 1, targets: 1 },
{ responsivePriority: 2, targets: -1 },
{ responsivePriority: 3, targets: 2 }
], fnCreatedRow: function( nRow, aData, iDataIndex ) {
if ( aData["status"] == "ready" ) { $('td', nRow).css('background-color', '#BEF781'); }
else if ( aData["status"] == "wait" ) { $('td', nRow).css('background-color', '#F2F5A9'); }
else { $('td', nRow).css('background-color', '#FFFFFF'); }
}})
});
var filteredData = tableRep.column(4).data().filter( function ( value, index ) {return value!="cancel" ? true : false;} );
答案 0 :(得分:0)
你试过这个选项吗?
var tableRep= $("#tblreport").dataTable({
//your config
})
.on('draw.dt', function () {
//Add here yours filters
});