html - HTML/TS 双搜索过滤器
问题描述
我有一个表,我想同时使用 2 列进行过滤。
<div class="form-row">
<div class="form-group ml-2">
<input
formControlName="serviceUser"
class="form-control w-230px"
type='text'
placeholder='Search by Name...'
(keyup)='filterByName($event)'
onClick="this.setSelectionRange(0, this.value.length)"
/>
</div>
<div class="form-group ml-2">
<input
formControlName="medication"
class="form-control w-230px"
type='text'
placeholder='Search by Medication...'
(keyup)='filterByMedication($event)'
onClick="this.setSelectionRange(0, this.value.length)"
/>
</div>
</form>
</div>
filterByName(event) {
const val = event.target.value.toLowerCase();
this.audits = this.temp.filter(function (d) {
return d.name.concat().toLowerCase().indexOf(val) !== -1 || !val;
});
}
filterByMedication(event) {
const val = event.target.value.toLowerCase();
this.audits = this.temp.filter(function (d) {
return d.medication.concat().toLowerCase().indexOf(val) !== -1 || !val;
});
}
过滤列时,只有第二个过滤器有效,并覆盖第一个过滤器。
解决方案
推荐阅读
- windows - 从右到左更改文本方向
- docker - 为什么我不能将新的 docker build 推送到 DockerHub repo
- workflow - Alfresco activiti 工作流程发起者 - 没有 QName 前缀,为什么?
- r - 通过 tinytex 成功安装 TinyTeX 后编译 test.tex 失败
- javascript - 如何在按钮单击和滚动时更新 window.location.hash?(使用历史 API)
- python - 即使我使用了异常处理,Selenium webdriver Python 也会抛出 TimeoutException
- javascript - Angular JS级联通知
- sql - BigQuery 使用 where 子句过滤表中并不总是存在的列
- html - 是否可以逐步加载每个 CSS 文件?
- rust - 根据初始未来结果有条件地链接 Rust 未来?