How to refresh meta.row after deleting a row?
How to refresh meta.row after deleting a row?
athaless
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 ???
This discussion has been closed.
Replies
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
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.
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 like1-api row().invalidate()
orrows().invalidate()
for Datatables to update its data cache.Kevin
... 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 + "'); ...";
} ...
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
Ohh sorry.
Here they are [ http://athenas.gauchafarma.com/legrand/_teste/TesteDataTables.html ]
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
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 ]
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