Modal popup in row with custom callback functions for buttons in popup

Modal popup in row with custom callback functions for buttons in popup

bearBEARbearBEAR Posts: 4Questions: 1Answers: 0

Hy,
I am looking how to solve following scenario:
1. user is looking at table(build by datatables :))
2. user decides row is not needed anymore and click on button in chosed line(example: https://editor.datatables.net/examples/simple/inTableControls.html)
3. for security purposes I need user to repeat line ID that will be deleted
4. once delete button in popup is clicked I will redirect user to another page(not clear if I will do it in .NET, java or flask but basicaly I will redirect ot backend, do some work here and returned new view)...and this is what I am loooking for basically: how to add custom callback function to above mentioned example

Any help for this would be appreciated since I am stuck on this :/
Thanks!

Answers

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    Are you wanting to do this with Editor specifically? If so, you could use the message() method, or message option of form-options to show a suitable message (since they allow HTML) - e.g.:

    Are you sure you wish to delete this entry? To confirm type the row’s ID <input id=“confirm”>
    

    Then use preSubmit to add that value to the Ajax request to the server so it can validate it (it must be done server-side since otherwise it would be trivial to bypass).

    Allan

  • bearBEARbearBEAR Posts: 4Questions: 1Answers: 0

    Thnks for help.
    No necessary in editor since Im using free version for now. I want to just have button where I define custom callback that redirects to backup with parameters from chosen line

  • bearBEARbearBEAR Posts: 4Questions: 1Answers: 0

    But including row in popup message is not possible as I can see?

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    Sure - use row().data() to get the data for a given row. e.g. you could use:

    table.row({selected: true}).data();
    

    to get the data for a selected row. Or if you’ve got an event handler being triggered inside the row:

    table.row($(this).closest(‘tr’)).data();
    

    Allan

  • bearBEARbearBEAR Posts: 4Questions: 1Answers: 0

    Thanks Allan. I just can't wrap my head around how to create button and modal dialog popup. Any examples for this?

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    If we take this example, in line 56 in the code shown below the table you could use:

    var data = table.row($(this).closest(‘tr’)).data();
    

    Then you have all of the row’s data in data. So you could do:

     message: 'Are you sure you wish to remove this record? First name is ' + data.first_name,
    

    Obviously that is specific to that example, so you’d need to modify it a bit for your data. And I’ve assumed you are using Editor, but even if not then the techniques are the same but way to use the data will be different based on whatever you are using.

    Allan

This discussion has been closed.