Data Tables Custom View then export to csv - problem
Data Tables Custom View then export to csv - problem
Hello and thanks for interesting in my problem.
I've got implemented database with datatables for equipment in company.
The problem is when I export my data to csv. Always every row is included into the csv file(I open it with excel), even when i custom view only a few of columns.
$( "#custom_print_view" ).dialog({
autoOpen: true,
modal: true,
height:400,
width:350,
buttons: {
"Show": function() {
$("#empty").dialog("close");
toShow.elements.push("inTime");
toShow.data = $("#custom_print_date").val();
if(toShow.elements.length >= 1){
$.post( baseUrl+"CustomPrint/download",{toShow: JSON.stringify(toShow)}).done(function(data){
data = JSON.parse(data);
columns = elementsToTable(toShow.elements);
update(data,columns);
//data = JSON.parse(data);
$('#exportLink').css('display', 'inline-block'); //show button when ready
var filename = 'hardware.csv'; //export .csv file
var blobby = new Blob([makeCSV(data)], {type: 'text/csv;charset=utf-8'}); //make blob object
$(exportLink).attr({
'download' : filename,
'href': window.URL.createObjectURL(blobby),
'target': '_blank'
});
})
}
else{
$("#empty").dialog("open");
}
$(this).dialog("close");
}
}
});
function update(data,columns){
var result='';
table = $('#Date').DataTable({
"pagingType": "simple",
"lengthMenu": [[50, 100, 150,200, -1], [50, 100, 150,200, "All"]],
"data": data,
"destroy": true,
"order": [[ 1, "asc" ]],
"scrollY": ($(window).innerHeight()-300)+"px",
"scrollCollapse": true,
"paging": true,
"columns": columns,
"columnDefs": [ {
"targets": 0,
"render": function ( data, type, full, meta ) {
if(data!=null)
{
return data.replace('"',"'");
}
else{
return data;
}
}
} ]
})
}
Where is the problem? I found on examples that it can work, and export only things that i searched through the search box or only the custom view with defined columns.
Please help me or ask me to copy other lines of code.
Cheers
This discussion has been closed.
Replies
I don't actually see where you are defining the CSV button for the Buttons extension. Is that is separate code?
Allan
and in another files .php there is:
<a id="exportLink">Export to CSV</a>
i've got it physically, problem is its data is not updating due to searching datables by search box
It looks to me like you are making a request to the server to get the data to export, so I don't really see how DataTables' filtering would come into play. You'd need the server to filter the data if you are getting it from there.
Allan