JSON file from filter view
JSON file from filter view

I am using the filter API calls to have a smart filter on columns of interest
function filterGlobal () {
$('#example').DataTable().search(
$('#global_filter').val(),
$('#global_regex').prop('checked'),
$('#global_smart').prop('checked')
).draw();
}
function filterColumn ( i ) {
$('#example').DataTable().column( i ).search(
$('#col'+i+'_filter').val(),
$('#col'+i+'_regex').prop('checked'),
$('#col'+i+'_smart').prop('checked')
).draw();
}
$(document).ready(function (){
$('#example').DataTable({
'ajax': 'static/js/test.ajax',
'columns': [
{
"render": function ( data, type, row, meta ) {
return '<a href="punchlist/edit/'+row.id+'">Edit</a>'; }
},
{ "data": "col1" },
{ "data": "col2" },
{ "data": "col3" },
{ "data": "col4" },
],
'dom': 'Rlfrtip'
});
$('input.global_filter').on( 'keyup click', function () {
filterGlobal();
} );
$('input.column_filter').on( 'keyup click', function () {
filterColumn( $(this).parents('tr').attr('data-column') );
} );
});
I generate a json file with all the start data with a server-side script. Now I understand the filter only modifies the table render. I would like to export the filter table to a json file, or to be able to get the filtered rows in whichever format available...
Is that possible using the datatables api?
thanks,
m.
This discussion has been closed.
Answers
You can get the row data using
rows().data()
. Use theselector-modifier
ofsearch:'applied'
. You may also want to usetoArray()
. You can then take the array of data and use a Javascript plugin to export to a JSON file.Kevin