How to render meta.row after deleting a row?

How to render meta.row after deleting a row?

hussein_97hussein_97 Posts: 2Questions: 0Answers: 0

columnDefs: [ {
{
targets:1,
render: (data, type, row, meta) => meta.row+1
}
} ]

my deleting function:
$('#example').on('click', 'td.editor-delete', function (e) {
var thisrow=$(this)
table.row(thisrow.parents('tr')).remove().draw(true);
})

my function is working perfectly with just one problem which is : after deleting the first row whose meta.row+1 = 1
the second row doesn't take the number 1 (instead of the deleted row) it still 2 it doesn't rendering meta.row after deleting
How to tackle this problem?

Replies

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    columns.render might not run after removing the row.

    Please describe how you are trying to use meta.row and maybe we can offer some suggestions.

    Kevin

  • hussein_97hussein_97 Posts: 2Questions: 0Answers: 0
    edited June 2022

    @kthorngren
    the only usage of meta.row in my website is just to add index to the rows
    so what I need is : to change rows meta.row when I remove one of those rows
    example
    the first row takes meta.row = 1 because I add 1 to meta.row
    the second row takes 2
    when I remove the first row whose meta.row is 1
    the second row still has meta.row = 2
    what I need is after removing the first one , second row should have the meta.row 1

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Where are you using these indexes?

    The meta.row value is only accessible in columns.render. columns.render doesn't always run and problem isn't after using row().remove(). This example it doesn't run after removing the row:
    http://live.datatables.net/gopedote/1/edit

    If you want to generate row indexes maybe this example will do what you want.

    Kevin

Sign In or Register to comment.