How to get filtered data
How to get filtered data
Hello,
I have this situation,
I select date period and get data from JSON to datatable by selected period,
then I make a column filtering in a header element. The filtering was working properly. But unfortunately I try to get filtered data and push it to array, but this not working.
In my situation, I will need to filter data by column with same name, put this data to array, and then from this array create a chat.
My code:
$(document).ready(function() {
var Info = []; // create an empty array
var Title = '';
var masyvas = '[';
var table = $('#example').DataTable( {
initComplete: function () {
this.api().columns(1).every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.header()).empty() )
.on( 'change', function () {
var val = $(this).val()
var filteredData = table.column(1).data().filter(function(v, i) {
if (val == v) {
// Reikia gauti eilutes indeksa!!! i netinka !!!
//var index = table.rows({"filter": "applied"}.data());
//var index = table._('tr', {"filter":"applied"});
var Tipas = table.row().data().Invoice[0].AmountType;
var Money = table.row().data().Invoice[0].Amount_money;
var kWh = table.row().data().Invoice[0].Amount_kWh;
if (Money > 0 || kWh > 0) {
Info.push({tipas : Tipas, money : Money, kwh : kWh});
console.log('DT Tipas: ' + Tipas + " | Money: " + Money + " | kWh: " + kWh + " | v: " + v + " | Val: " + val + " | I reiksme: " + i + " | index: " + index );
//}
Title = v + " - " + "<?=$_GET['periodas']?>";
}
});
$('#chart').empty(); // Clear a chat
drawChart(Title, Info); // Draw a chat
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
//column.data().unique().sort().each( function ( d, j ) {
column.data().unique().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' );
} );
} );
},
"dom": 'C<"clear">lfrtip',
"colVis": {
"buttonText": "Rodyti stulpelius"
//"activate": "mouseover"
},
"ajax": "data/m_suvartojimas.php?data="+"<?=$_GET['periodas'];?>",
"iDisplayLength": 25,
"scrollY": "300px",
"scrollX": "1000px",
"autoWidth": false,
"deferRender": true,
"fixedHeader": {
"header": true
},
"columns": [
{ "data": "Object.ObjID" },
{ "data": "Object.ObjName" },
{ "data": "Object.ObjType" },
{ "data": "Invoice[].InvoiceNumber" },
{ "data": "Invoice[].InvoiceSeries" },
{ "data": "Invoice[].AmountType" },
{ "data": "Invoice[].Amount_money" },
{ "data": "Invoice[].Amount_kWh" }
]
} );
May bee some one could take an advice.
try this method:
table.('tr', {"filter":"applied"});
or
table.('tr', {"search":"applied"});
} );