Removing rows

Removing rows

vic13vic13 Posts: 6Questions: 0Answers: 0
edited February 2011 in General
Just a quick heads up - In the past i've just done the $(this).parents('tr').remove(); call to remove rows from a table although have since found the example below;

http://www.datatables.net/examples/api/select_single_row.html

... i'd like to use the 'proper' way of removing rows from the datatable, although for some reason after i've deleted a row from the table, it doesn't then update the total # rows in the table, nor can you then show 'all' rows (it allows you to view upto the number you've removed - eg. if there are 57 rows, and I remove one (now 56 rows), it will let me view upto 50 rows but not 75 or all.

A JS error comes up when trying to view more than 50 rows (using the example above)...
Any ideas?

Is there the ability to pass oTable.fnDeleteRow(...) an instance of $('tr'); instead of what's in the example where you have to find the matching row in the fnGetNodes(..) function?

Great work otherwise, loving the pluggin! :)

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Allowing jQuery objects to be passed into the API functions is certainly something I'd like to do in future! At the moment you can pass in just a node to fnDeleteRow - so you could do $('tr')[0] - which will delete the first matched node.

    Regards,
    Allan
  • vic13vic13 Posts: 6Questions: 0Answers: 0
    Ah cheers - that makes my life a lot easier!
    Did you have any luck with updating the total # rows when using the fnDeleteRow(...) function or the JS error when switching to show different # of rows to 'all'?

    Thanks for your help - much appreciated! :)
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    $(this).parents('tr').remove(); will not work as expected with DataTables because you are removing a row from the DOM, but not from DataTables. You need to use fnDeleteRow - this will update the total number of rows and allow the pagination etc to work as expect.

    Allan
This discussion has been closed.