Reputation: 21
I'm using DataTables to create table. One of columns contains 'i' element and hidden input. I would like to filter data rows by that hidden value, but I can't manage to do that. As far I found that problem is in search() method, I suppose it doesn't search in children elements like 'input' in which I'm keeping my value. Code fragment:
var select = $('<select><option value=""></option><option value="true">Accepted</option><option value="false">Rejected</option></select>')
.appendTo($(column.footer()).empty())
.on('change', function () {
var val = $(this).val();
column.search(val, true, false) // problem is here
.draw(true);
});
Upvotes: 0
Views: 5924
Reputation: 21
Nevermind, I've managed to achieve this on my own. I needed to define "columnDefs" and inside this "targets" which are columns that you want to filter and "render". Here's the code:
var table = $('#dataCheck').DataTable({
"sDom": "ltp",
"columnDefs": [{
"targets": [6],
"render": function ( data, type, full, meta ) {
if(type === 'filter'){
return $('#dataCheck').DataTable().cell(meta.row, meta.col).nodes().to$().find('input').val();
} else {
return data;
}
}
}],
initComplete: function () {
this.api().columns().every(function (i) {
var column = this;
if (i == 6)
{
var select = $('<select><option value="..."></option><option value="true">Accepted</option><option value="false">Rejected</option></select>')
.appendTo($(column.footer()).empty())
.on('change', function () {
var val = $(this).val();
column.search(val, true, false)
.draw(true);
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
}
});
}
});
Upvotes: 2