The functionality I am seeking is as follows:
- User clicks button that sits inside a DataTable
- The button disables and its text changes from 'Manage' to an animated icon from the Font Awesome range of images.
- Ajax request is sent and on success a modal pops up with a new dialogue.
- The button reverts to it's original form.
Steps 1 and 3 are working fine, it is 2 and 4 that is giving me some issues. I recognise I need to use delegated event handlers to modify the specific button in the DataTable, at the moment there is no change on the page. It should be noted that the site uses Bootstrap.
Here is the column from the DataTable with my button:
"columns": [
...
{
"width": "8%",
"searchable": false,
"className": "customStyling",
"render": function () {
return '<button style="width: 75px" class="btn btn-primary">Manage</button>';
}
}
]
My onclick event:
$('#myTable tbody').on('click', 'button', function (e) {
// disable button & change text
$(this).prop("disabled",true);
$(this).text('<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>');
// get data from the relevant row
var row = myTable.row($(this).closest('tr'));
var data = row.data();
... AJAX REQUEST ...
... MODAL APPEARS ...
// enable button, change text back
$(this).prop("disabled", false);
$(this).text('Manage');
});
Any assistance is much appreciated.
$(this).text('<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>')tto$(this).html('<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>')lin your 2 step