[英]Select only filtered rows using select all button that comes with select extension in shiny's DT package
[英]Using select all script for filtered table
我正在使用此 ( 此處的文件 )腳本,並且正在使用第一行中的所有腳本檢查我的復選框。 但是首先,當我篩選列時,此腳本也選擇了隱藏行中的復選框。
$(document).ready(function(){
$('#select_all').on('click',function(){
if(this.checked){
$('.checkbox').each(function(){
this.checked = true;
});
}else{
$('.checkbox').each(function(){
this.checked = false;
});
}
});
$('.checkbox').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox').length){
$('#select_all').prop('checked',true);
}else{
$('#select_all').prop('checked',false);
}
});
});
感謝您的幫助。
使用jQuery :visible
選擇器可以忽略已過濾的復選框。 https://api.jquery.com/visible-selector/
$('#select_all').on('click',function(){
var doCheck = this.checked;
$('.checkbox:visible').each(function(){
this.checked = doCheck;
});
});
是的 我的新代碼:
$(document).ready(function(){
$('#select_all').on('click',function(){
if(this.checked){
$('.checkbox:visible').each(function(){
this.checked = true;
});
}else{
$('.checkbox:visible').each(function(){
this.checked = false;
});
}
});
$('.checkbox:visible').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox:visible').length){
$('#select_all').prop('checked',true);
}else{
$('#select_all').prop('checked',false);
}
});
});
謝謝大家...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.