如何使用Angular Material Data Table中的filterPredicate过滤开始日期和结束日期之间的数据? [英] How to filter out the data between a start and end date using filterPredicate in Angular Material Data Table?

查看:197
本文介绍了如何使用Angular Material Data Table中的filterPredicate过滤开始日期和结束日期之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据表中,我有一个开始日期"列和一个结束日期"列.而且我需要过滤掉开始日期和结束日期之间表格中的数据. 并使用此帖子,我能够编写过滤器谓词.但是它仅过滤确切的开始日期和确切的结束日期. 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 ?

推荐答案

首先,您需要添加范围"过滤器,或者在查询中添加范围必须"以获取所需日期之间的结果集.一旦获得正确的结果集,就可以根据需要聚合和过滤数据.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆