In WordPress, I am loading data with ajax in DataTables and all working fine with the ajax. Now I am trying to add one button to the order list so when admin clicks it will generate a PDF invoice. For that, I want to add additional columns to the datatable
. Referring to the document I am trying to use columnDefs
to add button as mentioned in doc.
HTML
...
<th class="heading-photo"><?php _e('Order Number', 'group-shop') ?></th>
<th class="heading-group"><?php _e('Gift', 'group-shop') ?></th>
<th class="heading-total-price"><?php _e('Total Price', 'group-shop') ?></th>
<th class="heading-delete"><?php _e('Status', 'group-shop') ?></th>
<!-- This column I have set to add Invoice button using columnDefs -->
<th class="heading-invoice invoice"><?php _e('Invoice', 'group-shop') ?></th>
...
Javascript
$('#gsAllOrdersTable').DataTable({
ajax: {
url: ajax_vars.ajax_url + '?action=gs_orders_dt_server'
},
columns: [
{data: 'order_number'},
{data: 'gifts'},
{data: 'total_price'},
{data: 'status'},
],
columnDefs: [{target: -1, data: null, defaultContent: '<button>Click!</button>'}],
lengthMenu: [[2, 10, 25, 50, -1], [2, 10, 25, 50, "All"]],
initComplete: function () {
this.api().columns().every(function () {
var column = this;
var input = document.createElement("input");
input.className = 'form-control';
$(input).appendTo($(column.footer()).empty())
.on('change', function () {
column.search($(this).val(), false, false, true).draw();
});
});
}
});
Question:
How to add additional column/s to datatable?