Add a row to the table using jQuery tablesorter.

I have a buil table with the jquery library "Tablesorter" and I want to add a row to this table when I click the button, but when I add a row, it does not take css tablesorter .. so I can not select it, or css "odd "" even "does not work.

$("#ajouterCodePiece").click(function(){
    $('#tablesorter-demo-gauche tr:last').after('<tr'><td>'+$('#codepiece option:selected').text()+'</td><td>'+$('#mode option:selected').text()+'</td></tr>');
});

How to do to add css and jquery tablesorter in my new line .. thanks

+4
source share
1 answer

Tablesorter stores the entire contents of the table in a cache, so to tell tablesorter that something has changed, you need to call an update:

$('table').trigger('update');

This update has been updated.

$("#ajouterCodePiece").click(function () {
    $('#tablesorter-demo-gauche tr:last').after('<tr><td>' + $('#codepiece option:selected').text() + '</td><td>' + $('#mode option:selected').text() + '</td></tr>');
    $('#tablesorter-demo-gauche').trigger('update');
});
+2
source

Source: https://habr.com/ru/post/1527916/


All Articles