Can someone explain me how can I add a css class to my checkbox I want to be able to highlight datatable row, but I also need to check the state of that checkbox so if=true highlight tr if not just reset it, I have a working checkbox but I don't understand how to make this, can someone please explain me how to make this work.
Checkbox label
render: function (data, type, row, meta) {
var checkedValue = (row['is_highlighted'] == 'TO_BE_PAID') ? "checked" : "";
return '<label class="input-control checkbox">' +
'<input class="highlight-toggle" type="checkbox" ' + checkedValue + '>' +
'<span class="check"></span>' +
'</label>';
}
Ajax call:
tableEl.on('change', '.highlight-toggle', function (e) {
var isHighlighted = {"is_highlighted": "TO_BE_PAID"},
unHighlighted = {"is_highlighted": "RESET"};
var row = invoicesTable.row($(this).parents('tr')),
rowData = row.data();
$.ajax({
headers: {
"X-CSRFToken": AppUtils.getCookie("csrftoken")
},
url: '/api/supplier_invoices/' + rowData["id"] + '/',
data: this.checked ? JSON.stringify(isHighlighted) : JSON.stringify(unHighlighted),
type: 'PATCH',
contentType: 'application/json'
}).done(function (success) {
row.data(success);
ClientNotifications.showNotification("Info", "Invoice status was updated", "success")
}).fail(function (error) {
row.data(rowData);
ClientNotifications.showNotification("Alert", "Invoice status was not updated: " + error['responseJSON']['detail'], "alert")
});
});
Aucun commentaire:
Enregistrer un commentaire