Layui Table Binding Event invalidation solution after clicking the Sort button

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.