Coexistence of multiple jquery. datatable and quick solution to all exceptions in checkbox _ javascript skills

Source: Internet
Author: User
This article mainly introduces the coexistence of multiple jquery. able and a quick solution to the exception of all checkbox selection. For more information, see. [Cause]

This should be a defect of the jquery. datatable control. The id of the checkbox plug-in this control is writable. Therefore, when multiple datatables are referenced to a page, all selected events match all datatable events, therefore, the checkbox of all multiple tables is selected.

[Solution]

Therefore, it is best to modify jquery. datatable control, assign different IDs to the checkbox under each generated datatable, because the datatable id is different, therefore, you can use the datatable id as the checkbox prefix to form a unique id. The checkbox call event also needs to be replaced with the new id to call the event.

[Modifying files]

Jqurey. datatable. ext. js (v0.0.1)

1. Modify the init method:

The Code is as follows:


$ ("#" + Options. select_table). find ('thead tr th: first-child ')
. Prepend ('');

==>

$ ("#" + Options. select_table). find ('thead tr th: first-child ')
. Prepend ('');


2. Modify the subscribeAllChk method:

The Code is as follows:


$ ("# Chk_all"). click (function (){

==>

$ ("#" + $. Fn. datatable_ext.defaults.select_table + "_ chk_all"). click (function (){


3. Modify the subscribeChk method:

The Code is as follows:


If (checked_chk_num = curr_page_chk_num ){
$ ("# Chk_all"). attr ('checked', 'checked ');
} Else {
$ ("# Chk_all"). removeAttr ('checked ');
}

==>

If (checked_chk_num = curr_page_chk_num ){
$ ("#" + $. Fn. datatable_ext.defaults.select_table + "_ chk_all"). attr ('checked', 'checked ');
} Else {
$ ("#" + $. Fn. datatable_ext.defaults.select_table + "_ chk_all"). removeAttr ('checked ');
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.