【发布时间】:2018-10-01 13:25:26
【问题描述】:
我希望这里的人能够帮助我,我正在尝试创建一个可以通过使用 2 个下拉列表过滤的应用程序和服务器列表(因为有超过 100 行的数据在表中。
到目前为止,我已经过滤掉了应用程序名称或服务器功能的表格,我现在想要工作的是表格过滤器基于两个选择。
因此,目前如果我从第一个下拉菜单中选择 APP1,它将显示 APP1 的所有条目,但是如果我尝试选择 DB 服务器,它将显示所有具有 DB 服务器的应用程序,而不仅仅是显示 APP1 的 DB 服务器。
由于公司政策,我无法提供表格的正文/内容,但我至少提供了第一行,其中包含标题。
我无法访问 jfiddle 或类似的东西来给出一个工作示例,因为它被我工作的公司阻止。
希望我提供的信息就足够了。
提前致谢。
$(document).ready(function () {
$("#application").on("change",
function(){
var appName = $(this).find("option:selected").html();
$("table tr td:first-child").each(
function(){
if($(this).html() != appName){
$(this).parent().hide();
}
else{
$('#titles').show();
$(this).parent().show();
}
});
});
$("#function").on("change",
function(){
var functionName = $(this).find("option:selected").html();
$("table tr td:first-child").next().each(
function(){
if($(this).html() != functionName){
$(this).parent().hide();
}
else{
$('#titles').show();
$(this).parent().show();
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div title="Select Application"">
<strong>Select Application</strong><br>
<select id="application" class="form-control selectpicker">
<option value="">--Select--</option>
<option value="">APP1</option>
<option value="">APP2</option>
<option value="">APP3</option>
<option value="">APP4</option>
<option value="">APP5</option>
<option value="">APP6</option>
<option value="">APP7</option>
<option value="">APP8</option>
<option value="">APP9</option>
<option value="">APP10</option>
<option value="">APP11</option>
<option value="">APP12</option>
</select>
</div>
<br>
<div title="Select Server Function"">
<strong>Select Application</strong><br>
<select id="function" class="form-control selectpicker">
<option value="">--Select--</option>
<option value="">DB Server</option>
<option value="">Automate Job Server</option>
<option value="">Web Server</option>
<option value="">Application Server</option>
<option value="">Database & Application Server</option>
<option value="">Citrix Server</option>
<option value="">Inbound/Outbound Server</option>
<option value="">COMMS Server</option>
<option value="">WEBFARM Servers</option>
<option value="">WAS Instances</option>
<option value="">APP/Web Server</option>
<option value="">Autosys</option>
<option value="">Qlik Sense Server</option>
</select>
</div>
<br>
<table style="width: 733.38px;" class=">
<tbody>
<tr style="height: 20px;" id="titles";>
<td style="width: 147px; height: 20px;"><strong>Application Name</strong></td>
<td style="width: 162px; height: 20px;"><strong>Function</strong></td>
<td style="width: 256px; height: 20px;"><strong>Server Name</strong></td>
<td style="width: 138.38px; height: 20px;"><strong>ENVIRONMENT</strong></td>
</tr>
<tr style="height: 20px;">
<td style="width: 147px; height: 20px;">APP1</td>
<td style="width: 162px; height: 20px;">DB Server</td>
<td style="width: 256px; height: 20px;">ServerName</td>
<td style="width: 138.38px; height: 20px;">PROD</td>
</tr>
<tr style="height: 20.5px;">
<td style="width: 147px; height: 20.5px;">APP1</td>
<td style="width: 162px; height: 20.5px;">App Server</td>
<td style="width: 256px; height: 20.5px;">ServerName</td>
<td style="width: 138.38px; height: 20.5px;">COB</td>
</tr>
<tr style="height: 20px;">
<td style="width: 147px; height: 20px;">APP2</td>
<td style="width: 162px; height: 20px;">DB Server</td>
<td style="width: 256px; height: 20px;">ServerName</td>
<td style="width: 138.38px; height: 20px;">UAT</td>
</tr>
<tr style="height: 20px;">
<td style="width: 147px; height: 20px;">APP3</td>
<td style="width: 162px; height: 20px;">DB Server</td>
<td style="width: 256px; height: 20px;">ServerName</td>
<td style="width: 138.38px; height: 20px;">PROD</td>
</tr>
【问题讨论】:
-
可以添加一些示例记录吗?
-
我已按要求添加了一些示例记录,由于公司政策,必须使其具有通用性。
标签: javascript jquery html html-table show-hide