DataTables Table Tools - Deleting a row after inserting it

DataTables Table Tools - Deleting a row after inserting it

jLinuxjLinux Posts: 981Questions: 73Answers: 75
edited September 2012 in General
Basically, im trying to combine this:
http://datatables.net/release-datatables/examples/api/select_single_row.html

With this:
http://datatables.net/release-datatables/examples/api/add_row.html

The JS and CSS link directly to the DataTables site, just for testing.
http://pastebin.com/2DQX68H0

basically, it allows me to delete the existing rows, but the ones I insert, wont get deleted. Im guessing its because it gets a list of tables when the document loads, and thats what it uses to reference when it deletes rows. Im somewhat new to jQuery and DataTables, so any help would be appreciated.

Thanks in advance!

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > $("#example tbody tr").click( function( e ) {

    Change that for:

    [code]
    $("#example tbody").on('click', 'tr', function( e ) {
    [/code]

    and that should do it. See http://datatables.net/faqs#events for more information about it.

    Regards,
    Allan
  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited September 2012
    Dude you're awesome, thank you!

    What about having this delete multiple rows? I got it to select it, but im guessing this part..
    [code]if ( anSelected.length !== 0 ) {
    oTable.fnDeleteRow( anSelected[0] );
    }[/code]
    needs a loop in it.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Yes exactly - just put a `for` loop over that deleting anSelected[i]. The API in 1.10 will be must more flexible in that regard allowing you to pass in an array of nodes to be deleted.

    Allan
This discussion has been closed.