There are several ways to accomplish this but this is the way I would do it:
Add the user buttons like this:
- Code: Select all
$userButtons[] = array(
'button_html' => '<button onclick="'.$this->mateInstances[0].'.handleCustomExport();">Custom Export</button>'
);
$this->Editor->setConfig('userButtons',$userButtons);
Add a new javascript function in the ajax_table_editor.js file, inside the mate object like this:
- Code: Select all
handleCustomExport: function() {
var selectedRows = this.getSelectedRows();
var numRows = Object.size(selectedRows);
var sessionData = this.getSessionData();
if(numRows == 0) {
this.showTooltipMsg(mateSelectRow);
} else {
var selectedRowsArray = []
for (var key in selectedRows) {
selectedRowsArray.push(selectedRows[key])
}
window.location.href = 'ProDemo.php?custom_export=1&selected_rows=' + selectedRowsArray.join(',') + '&session_data='+encodeURIComponent(sessionData);
}
},
And add the following code in the constructor of the config file (in this case it would be ProDemo.php)
- Code: Select all
else if(isset($_GET['custom_export']))
{
$this->Editor->data['sessionData'] = $_GET['session_data'];
$this->Editor->setDefaults();
ob_end_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-type: application/x-msexcel');
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.$this->Editor->tableName.'.csv"');
// Add utf-8 signature for windows/excel
echo chr(0xEF).chr(0xBB).chr(0xBF);
$escapedRowIds = [];
foreach (explode(',', $_GET['selected_rows']) as $id) {
$escapedRowIds[] = $this->escapeData($id);
}
$this->Editor->sqlFilters = "id in (" . implode(',', $escapedRowIds) . ")";
echo $this->Editor->exportInfo();
exit();
}
After adding that code, it should work.