The only cross-browser way to do this at the moment would be with a setInterval and possibly a custom event.
setInterval(function() {
var $t = $("#myTable"),
rowCount = $t.data("rowCount"),
rowLength = $t.find("tbody").children().length;
if (rowCount && rowCount !== rowLength) {
$t.trigger("rowcountchanged").data("rowCount", rowLength);
}
else if (!rowCount) {
$t.data("rowCount", rowLength);
}
}, 50);
$("#myTable").on("rowcountchanged",function(){
alert($(this).data("rowCount"));
});
I would suggest triggering the event manually when you change the number of rows rather than using an interval if possible.
UPDATE:
Use the jqGrid refresh
event.
var rowCount = $("#gridid>tbody>tr").length;
jQuery("#gridid").jqGrid({
...
refresh: function(){
var currCount = $("#gridid>tbody>tr").length;
if (currCount !== rowCount) {
alert("Number of rows changed!");
rowCount = currCount;
}
},
...
});
If you are manually deleting any rows on click, you will need to run your code there too unless it is also reloading the grid.