How to make some column to have [Edit][Delete] buttons and perform function accordingly?

How to make some column to have [Edit][Delete] buttons and perform function accordingly?

caotunspringcaotunspring Posts: 5Questions: 3Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: Able to perform server side to get records and show on html, additionally need to have action on row basis as well, to edit and to delete

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    Are you using Editor for this? If so see this example.

    IF not this example shows how to create buttons and event handlers for them to get the data:
    http://live.datatables.net/xijecupo/1/edit

    Kevin

  • caotunspringcaotunspring Posts: 5Questions: 3Answers: 0

    Yes, I got the idea. Thanks a lot!
    It shows the two buttons.
    Next, how to get selected row's data for that button to perform js function?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited August 2021 Answer ✓

    There are two event handlers in the example, one for each button that gets the data For example:

    $('#example tbody').on('click', '.name', function () {
      var row = $(this).closest('tr');
      
      var data = table.row( row ).data().name;
      console.log(data);
    });
    

    Also this example might help. Yo will want to understand jQuery delegated events.

    Kevin

  • caotunspringcaotunspring Posts: 5Questions: 3Answers: 0

    Thanks a lot!
    For my case, I need to get Id from selected row.

    Follow sample style,

    • var data = table.row( row ).data().name;
    • var Id = table.row( row ).data().Id;

    It works!

Sign In or Register to comment.