1
我有一個表格,我想對其應用3個過濾器。 2是選擇,1是搜索輸入。我唯一的問題是,如果我先使用搜索輸入,然後選擇其他2個過濾器中的任何一個,搜索輸入過濾器將被忽略。jquery中的組合表格過濾器
這是因爲我有$(this).show();命令(第6行)在foreach中檢查每個錶行是否具有要顯示的條件。 但是,我不知道如何擺脫它,仍然使腳本工作。 任何想法?
這裏是我的代碼:
$("select#role_filter, select#type_filter").change(function() {
var role = $("select#role_filter option:selected").text();
var type = $("select#type_filter option:selected").text();
var type_val = $("select#type_filter option:selected").val();
$('#access-points > tbody > tr').each(function() {
$(this).show();
if (role != 'Display all') {
var tooltips = $(this).find('td:first-child').attr('tooltips').split(', ');
if (jQuery.inArray(role, tooltips) == -1) {
$(this).hide();
}
tooltips = [];
}
if (type != 'Display all') {
var point_type = $(this).attr('point_type');
if (point_type != type_val) {
$(this).hide();
}
}
});
});
$("input#search_table").on("keyup", function() {
var search = $(this).val();
$('select#role_filter, select#type_filter').trigger('change');
$('#access-points > tbody > tr').each(function() {
if ($(this).css('display') != 'none') {
if ($(this).attr('access_point').toLowerCase().indexOf(search.toLowerCase()) === -1)
$(this).hide();
else
$(this).show();
}
});
});
不要使用此'$( 「#選擇role_filter,選擇#type_filter」)'使用這個:'$( 「#role_filter,#type_filter」)'的ID是最快的選擇和獨特的和其他人只是放慢速度。 –
如果你設置了一個演示,那將會更容易幫助你。 – Mottie