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