How to send a ajax request as same as for create, edit and delete when custom button is clicked
How to send a ajax request as same as for create, edit and delete when custom button is clicked
Hi Allan,
I have created a customer button called "Suspend" as shown bellow. Could you please help me in sending a ajax request to the server when "suspend" button is clicked. My requirement is that when I select a row and click on suspend button, I need to update the row status to false in the database and remove the same from data table if the request is successful.
buttons: [
{extend: "create",editor: editor,formButtons: [{ label: 'Cancel', fn: function () { this.close(); }},'Save']},
{extend: "edit",editor: editor,formButtons: [{ label: 'Cancel', fn: function () { this.close(); }},'Update']},
{extend: "selectedSingle",text: "Suspend",editor: editor,action: function ( e, dt, node, config ) { },
{extend: "remove",editor: editor,formButtons: [{ label: 'Cancel', fn: function () { this.close(); }},'Delete']}]
I can send a jquery ajax request, but don't know how to display a progress bar as the data table does it when sending ajax requests.
Answers
You would need to use an
action
option as a function (buttons.buttons.action
) and have it calledit()
to edit the selected row. Then usefield().val()
to set the value andsubmit()
to submit the form.Apply a condition to the server-side code so that if the update happens, the row is excluded from the data set.
Allan