Re-page after removing a row

Re-page after removing a row

tortor Posts: 3Questions: 0Answers: 0
edited September 2013 in DataTables 1.9
I swear I've looked everywhere and can't find the answer.

Let's say I use .fnDeleteRow to remove a row. Now my page has 9 rows. How do I bump the next row from the next page in? AKA, how do I quickly re-paginate after changing DataTables' rows? Do I need to push this changed data back into the table's value and then force a redraw?

Thanks

Replies

  • allanallan Posts: 63,281Questions: 1Answers: 10,425 Site admin
    DataTables will do a full redraw on row delete, so this should be happening already I think. The only place where it won't is on the last page. Can you link us to and example please?

    Allan
  • tortor Posts: 3Questions: 0Answers: 0
    edited September 2013
    Hey Allan, thanks for the response. I have hastily thrown my work online so that you can at least see what I'm trying to do (some of the pages seem to have broke compared to my local copy but that's another problem...).

    If you hit http://torrobinson.com/test/public/stats/edit and log in with "allan", password "123123". Then when you are redirected, pick the first menu item from the dropdown. Info from my db is loaded in, including a bunch if line items into a Datatables.js table (the Date/Value/Actions table).

    Each line has a little red delete button. When this is clicked (and maybe you can see my javascript if you inspect with Chrome) I grab that tr:

    [code] var tr = $(this).parents('tr').first();[/code]

    Then I delete it:

    [code]statTable.fnDeleteRow(tr);[/code]

    It vanishes as expected, but paging doesn't go anywhere. I haven't yet implemented actually hitting the db first to try perform a successful deletion, I'm just trying to get it to display right first.

    I'm initializing the table with these options:

    [code] var statTable = $('#statTable').dataTable({
    "bFilter": false,
    "bLengthChange": false,
    "aaSorting": [],
    "fnDrawCallback": null,
    "iDisplayLength":10
    });[/code]

    Is there anything wrong with my initialization and row deletion?

    Note that when the page gets down to 1 row left, then it fills back to always have 1 row, not 10, and the total count never changes,

    Thanks so much

    EDIT: Please note I havent begun rebinding these delete buttons on page changes. I want to see first that I can enter on the 1st page, delete a row, and watch the page refill to 10 and the count go down by one. In other words, if you change to page 2, the delete button wont function.
  • tortor Posts: 3Questions: 0Answers: 0
    I've fixed the issue - turns out the remove would remove the row but then was failing elsewhere in the plugin itself. I guess I was passing in the results from a jQuery selector, which was passing in an array of elements. Once I added a [0] on, it began functioning correctly. Thanks
This discussion has been closed.