I have a list and by making use of datatable plugin I sort them clearly. Before that by php coding only I make the sorted list. And according to the current list, I can export to csv file.My code was like:
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
$rows = mysql_query(base64_decode($_REQUEST['qur']));
$number = mysql_num_rows($rows);
if($number > 0){
fputcsv($output, array('Name','Username','Email','Age','Location','Contact','Privilege','JoiningDate','Status'));
// loop over the rows, outputting them
$blankArray = array();
while ($row = mysql_fetch_assoc($rows)) {
$name = $row['admin_name'];
$username = $row['username'];
$email = $row['email'];
$age = $row['age'];
$location = $row['location'];
$cont = $row['contact_no'];
$priv = get_role_name_by_id($row['role']);
$doj = substr($row['creation_date'],0,10);
$status = ($row['status'] == '1')?"enable":"disable";
$blankArray['Name'] = $name;
$blankArray['Username'] = $username;
$blankArray['Email'] = $email;
$blankArray['Age'] = $age;
$blankArray['Location'] = $location;
$blankArray['Contact'] = $cont;
$blankArray['Privilege'] = $priv;
$blankArray['JoiningDate'] = $doj;
$blankArray['Status'] = $status;
fputcsv($output, $blankArray);
}
}else{
fputcsv($output, array('No Record Found'));
}
And from the page I was using the following piece of code:
<a href="export.php?report=user&qur=<?php echo base64_encode($search_sql); ?>"><button>Export to CSV</button></a>
Now As I change the sorting option in datatable plugin,and I use the following code :
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "datatabledb.php",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
//"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [
{
"sExtends": "copy",
"sButtonText": "Copy to clipboard"
},
{
"sExtends": "csv",
"sButtonText": "Save to CSV"
},
{
"sExtends": "xls",
"sButtonText": "Save for Excel"
}
]
}
} );
But still it is not showing the button also. Please help me.
You can use the TableTools that does what you need.
See this Link! for an example and see this link for the documentation!