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

vkurimetivkurimeti Posts: 6Questions: 4Answers: 0
edited November 2016 in Free community support

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

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin

    You would need to use an action option as a function (buttons.buttons.action) and have it call edit() to edit the selected row. Then use field().val() to set the value and submit() 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

This discussion has been closed.