Recent projects using Layui more frequently, encountered a troublesome problem, online search also did not see the same type of problem, so write down.
The requirement is to click on a cell in the right-hand table, which will trigger the click event as follows code:
$ ("TABLE>TBODY>TR>TD"). Click (function () {
chickstr=$ (This). attr ("Data-field");
if (typeof (chickstr) = = ' String ') {
if (Chickstr.indexof ("Indicode")! =-1) {
Chickstr=chickstr.charat (chickstr.length-1);
}
}
});
When the page is refreshed, the above trigger event is valid and executes without clicking the Sort button on the left indicator rank, but when the Sort button is clicked, the triggering event above is invalid .
The reason is that after Layui click Sort, the table is re-assembled and the original binding event is invalidated.
Workaround: In the last side of the method that triggers the Sort button, re-bind the point-click event for the table.
Table.on (' Sort (demoevent) ', function (obj) {
... ..
Table.reload (TableID, {
...
});
///Here you need to re-bind the fixed-point event to the cell, since Layui click Sort, the table is re-assembled, the original binding event is invalidated
$ ("TABLE>TBODY>TR>TD"). Click (function () {
chickstr=$ (this). attr ("Data-field");
if (typeof (chickstr) = = ' String ') {
if (Chickstr.indexof ("Indicode")! =-1) {
Chickstr=chickstr.charat (chickstr.length-1);
}
}
});
});
Layui Table Binding Event invalidation solution after clicking the Sort button