How to refresh meta.row after deleting a row?

How to refresh meta.row after deleting a row?

athalessathaless Posts: 6Questions: 0Answers: 0

Humm...
My problem is after removing a row, the index (meta.row) in "render" is outdated.

{ ...
"Data": "grade",
"render": function ( data, type, row, meta ) {
return "

<

div span=\"myDeleteRow('" + meta.row + "');\" </div>";
}
} ...

any suggestion ???

Replies

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    Not sure I understand what you mean by outdated. If the row is in the table then meta.row should contain the row index. Does it not?

    Maybe you can post a link to your page or a test case replicating the issue. Please provide details of how to replicate the issue and what you expect meta.row to be.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • athalessathaless Posts: 6Questions: 0Answers: 0
    edited October 2018

    Well (sorry for my limited english).

    When rendering some column, I put "meta.row" as a parameter for a myDeleteRow function. In that function I delete that line by its index ("meta.row"). In the grid the other lines still contain the "render" with the original meta.row as parameter to myDeleteRow, without considering that this line has been removed.

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    Maybe the question is how are you removing the row?

    If you are not using Datatables API like row().delete() then Datatables doesn't know about the deletion. If using something other than Datatables API's then you will need to use something like 1-api row().invalidate() or rows().invalidate() for Datatables to update its data cache.

    Kevin

  • athalessathaless Posts: 6Questions: 0Answers: 0
    edited October 2018

    ... here is my function

    function myDeleteRow(prIdx) {
    var table = new $.fn.dataTable.Api( '#dataTables-1' );
    table.row(prIdx).remove().draw(true);
    }

    and on render a wrote this code
    ...
    "Data": "grade",
    "render": function ( data, type, row, meta ) {
    return "... span=myDeleteRow('" + meta.row + "'); ...";
    } ...

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @athaless ,

    We're happy to take a look. As per the forum rules, if you could link to a running test case showing the issue we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • athalessathaless Posts: 6Questions: 0Answers: 0
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That page isn't loading, I'm afraid. Could you also give some steps on how to reproduce and what the desired results should be.

    Thanks,

    Colin

  • athalessathaless Posts: 6Questions: 0Answers: 0

    Ohhh..
    Sorry, my mistake... I need to ask my boss to give external permission for this server. Now it's fine

    [http://athenas.gauchafarma.com/legrand/_teste/TesteDataTables.html ]

    and some explain image, before delete some row(s), this happen [ http://athenas.gauchafarma.com/legrand/_teste/ExemploErro.jpg ]

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @athaless ,

    Yep, that won't work, as the row Id can't be determined at render, since that's
    a snapshot in time at the point of creation. If rows are then removed before that one, it shuffles the numbers, so it'll have no meaning.

    The tidiest way to do this would be to do something like this example here. Have a class for the last column or the bin icon, and have a click event that does the delete. As shown in that example, it's trivial to get the row that was clicked.

    Hope that helps,

    Cheers,

    Colin

This discussion has been closed.