繁体   English   中英

如何在带有 Odata 的 aurelia slickgrid 中使用 gt/le 运算符

[英]How to use gt/le operator in aurelia slickgrid with Odata

我想在 odata 请求中发送我自己的运算符,而不是使用 aurelia slickgrid 内置的“eq”运算符。

这是我的列定义

{
                id: 'LockoutEndDateUtc', name: 'Status', field: 'LockoutEndDateUtc', minWidth: 85, maxWidth: 95,
                type: FieldType.boolean,
                sortable: true,
                formatter: Formatters.multiple,
                params: { formatters: [this.StatusFormatter, Formatters.checkmark] },
                filterable: true,
                filter: {
                            collection: [ 
                                { value: 'le ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'True' }, 
                                { value: 'gt ' + (() => {const dt = new Date(); return dt.toISOString().split('.')[0] + "Z";})(), label: 'False' }
                            ], //['', 'True', 'False'],
                            model: Filters.singleSelect,//multipleSelect//singleSelect,
                        }
            }

这是用户界面在此处输入图像描述

这就是请求过滤器的样子..

$filter=(LockoutEndDateUtc%20eq%20le%202022-06-28T12%3A59%3A25Z)

如果我从上述请求中删除 %20eq,其他一切正常。 所以我的问题是如何删除 %20eq。 或者我如何在请求中发送我自己的 gt, le。

您不能在布尔过滤器上真正做到这一点(但是您可以在带有operator的日期过滤器上做到这一点)而且我认为我没有添加任何方法来按照您想要的方式提供自定义过滤器搜索,但由于您使用的是 OData,因此您有更多的控制权,您可以自己更改查询字符串。 需要明确的是,根本不建议更改 OData 查询字符串,这是最后的解决方案,风险自负,但对于您的用例,它可能是实现您想要的唯一方法。

prepareGrid() {
    this.gridOptions = {
      // ...
      backendServiceApi: {
        service: new GridOdataService(),
        process: (query) => this.getCustomerApiCall(query),
      } as OdataServiceApi
    };
  }
}

getCustomerApiCall(query: string) {
  let finalQuery = query;
  // in your case, find the boolean value from the column and modify query

  // your logic to modify the query string
  // untested code, but it would probably look similar
  if (query.includes('LockoutEndDateUtc%20eq%20true')) {
    // calculate new date and replace boolean with new date
    finalQuery = query.replace('LockoutEndDateUtc%20eq%20true', 'LockoutEndDateUtc%20le%202022-06-28T12%3A59%3A25Z');
  }
  return finalQuery;
}

另一种可能的解决方案,但需要更多的工作。

如果我使用常规网格,没有后端服务并且无法访问查询字符串,我可能会在网格外部添加一个外部下拉列表,并添加日期列,然后使用动态过滤控制网格中的过滤器. 您可以在Example 23看到一个演示,原则是您保持列的真实性质(在您的情况下为日期)并对其进行过滤,如果您想要“低于今天的日期”之类的内容,则添加一种外部动态过滤方式(a按钮或下拉菜单)并动态控制过滤器,如下所示(来自示例 23)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM