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 ');
}