데이터 테이블 1.10 및 YADCF 0.8.9.beta.24를 사용하고 있습니다.활성/비활성 YADCF 필터에 대한 이벤트 핸들러
내 필터 입력은 각 테이블 헤드 th
의 드롭 다운 메뉴에 표시됩니다. 필터가 적용된 th
에 활성 필터 아이콘을 표시하거나 숨기고 싶지만 다른 YADCF 필터 유형으로 이벤트를 변경/선택/제거하는 방법을 잘 모릅니다. 특히 YADCF 지우기 버튼. (전 select2
, text
, range_date
및 auto_complete
입니다.)
$('#my-table thead').on('change', function(e) {
if($(e.target).val()) {
$(e.target).closest('th').addClass('filtered_col');
} else {
$(e.target).closest('th').removeClass('filtered_col');
}
});
//Change event triggers when selecting with 'select2'
//and when removing items with Select2 remove button,
//works also selecting with 'auto_complete' filters
//but not whith any YADCF clear button
//or when selecting with type 'text' or 'range_date'.
내가 선택 2 필터 ('선택'과 '제거')에 대한 특정 이벤트 hanlers로하려고했으나 YADCF 지우기 버튼을 사용하는 경우 그 해고되지 않습니다
내가 뭘하려합니다.나는 또한 시도 :
그래서oTable.on('search.dt', function() {
$(this).find('th').each(function() {
if ($(this).find('.select2-search-choice').length || $(this).find('.inuse').length) {
$(this).addClass('filtered_col');
} else {
$(this).removeClass('filtered_col');
}
});
});
//It works selecting with 'auto_complete' and with 'text' types.
//and with respective YADCF Clear button.
//also selecting with 'select2' type and clearing with Select2 clear button,
//but NOT clearing select2 with YADCF clear button
//'range_date' is not being targeted here.
는 어떻게 표시하고 사용자가 각 열을 필터링 할 때 활성 아이콘을 숨길 능동 필터에 반응 할 수 있을까?
편집 : 나는 그들을 트리거하기 위해, jQuery의 addClass
/removeClass
을 수정하기 위해 지금 노력,
$('#main_container').find('.yadcf-filter-wrapper').bind('DOMSubtreeModified', function(e) {
if($(e.target).closest('th').find('.select2-search-choice').length || $(e.target).closest('th').find('.inuse').length) {
$(e.target).closest('th').addClass('filtered_col');
} else {
$(e.target).closest('th').removeClass('filtered_col');
}
});
//Event is only firing with 'select2' filtering and clearing
//No other filter types are firing this event, although one CSS class is being added in 'text' filters.
김을 : 다니엘의 대답 @에서 제안한 것처럼 (나는 DOMSubtreeModified
을 청취하려고 :) 감사합니다 (로 this answer에서 제안) 일부 이벤트는 :
(function(){
var originalAddClass = jQuery.fn.addClass;
var originalRmvClass = jQuery.fn.removeClass;
jQuery.fn.addClass = function(){
// Execute the original method.
var result = originalAddClass.apply(this, arguments);
// trigger a custom event
jQuery(this).trigger('cssClassAdded');
// return the original result
return result;
}
jQuery.fn.removeClass = function(){
var result = originalRmvClass.apply(this, arguments);
jQuery(this).trigger('cssClassRmvd');
return result;
}
})();
// And then..
$(function() {
$('.yadcf-filter-wrapper').on('cssClassAdded', function(){
if($(this).closest('th').find('.select2-search-choice').length || $(this).closest('th').find('.inuse').length) {
$(this).closest('th').find('.fa-filter').css('display', 'block');
}
});
$('.yadcf-filter-wrapper').on('cssClassRmvd', function(){
if(!$(this).closest('th').find('.select2-search-choice').length && !$(this).closest('th').find('.inuse').length) {
$(this).closest('th').find('.fa-filter').css('display', 'none');
}
});
});
//This is the best approach, since is working with 'text', 'select2' and 'auto_complete', with both filtering and clearing actions.
//'range_date' is the only one I still need to cover.
As이 마지막 예제와 나는 모든 필터 유형의 문제가 있지만, 'range_date'를 해결할 수 말했다. @Daniel이 제안한대로, YADCF를 수정하여이 클래스에 몇 가지 클래스를 도입하는 유일한 아이디어가 있습니다 (이를 피하기 위해 manteinance 이유로 인해).
나는 'inuse'클래스가 range_date
필터에도 추가 될 것으로 예상했다. 마지막 접근 방식으로 트릭을 수행합니다. YADCF는 어떤 필터 유형에 대해서만이 클래스를 소개하고 모든 필터 유형에 대해서 소개하는 것이 아닙니다. 어쩌면 내가 뭔가를 놓친거야?
나는 특히 해결할 수없는 'range_date'를 위해이 문제를 해결하는 더 좋은 해결책을 고맙게 생각합니다.
감사
필터가inuse
클래스가 제거되고 해제 될 때 사용 yadcf의 필터는 필터에 클래스
inuse
를 추가하고 때 때문에 필터의 변경 이벤트는 DOM들을 시도 할 수
감사합니다 귀하의 빠른 답변을 위해. 그러나 실제로 'select2'필터 만이 'DOMSubtreeModified' 이벤트를 발생시키고'text ','date-range '및'auto_complete '는 없습니다 ('텍스트 '필터의 경우에는 inuse 클래스가 추가되지만) . – chimos
제발 내 질문에 '편집'을 참조하십시오. – chimos