如何使用 Angular Material Data Table 中的 filterPredicate 过滤掉开始日期和结束日期之间的数据? [英] How to filter out the data between a start and end date using filterPredicate in Angular Material Data Table?
问题描述
在我的数据表中,我有一个开始日期列和一个结束日期列.我需要过滤掉开始日期和结束日期之间的表中的数据.并使用此帖子 ,我能够编写过滤器谓词.但它只过滤确切的开始日期和确切的结束日期.API 以字符串格式返回日期,例如2018-08-30".那么,如何过滤掉开始日期和结束日期之间的数据?
In my data table I have a Start date column and an end date column. And I need to filter out the data in the table between the start and end dates. And using this post , I was able to write the filter Predicate. But it only filters the exact start date and exact end date. The API returns the date in a string format like "2018-08-30". So, how to filter out the data between the start and end dates ?
推荐答案
首先,您需要添加 Range 过滤器,或者 Range must 在您的查询中获取所需日期之间的结果集.获得正确的结果集后,您可以根据需要对数据进行聚合和过滤.
First, you need to add the Range filter, or Range must in your query to get the result set between the required dates. Once you got the correct result set, then you can aggregation and filter the data according to you requirement.
POST _search
{
"query": {
"bool": {
"filter": [
{
"range": {
"endDate": {
"gte": "2018-07-30",
"format": "yyyy-MM-dd"
}
}
},
{
"range": {
"startDate": {
"lte": "2018-08-30",
"format": "yyyy-MM-dd"
}
}
}
]
}
}
}
希望这能解决您的问题.
Hope this will solve you problem.
这篇关于如何使用 Angular Material Data Table 中的 filterPredicate 过滤掉开始日期和结束日期之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!