简体   繁体   English

ag-grid自定义过滤器实现

[英]ag-grid custom filter implementation

I would like to make a react floating date filter that works exactly like the default filter. 我想做一个反应浮动日期过滤器,其工作原理与默认过滤器完全相同。 The default filter has equals, greater than, less than, not equal and in range. 默认过滤器的范围等于,大于,小于,不等于。 I would like to preserve the behavior of these filters. 我想保留这些过滤器的行为。 The only things that I would like to change is the input format . 我唯一想更改的是输入格式 The input format of the date is for the default is mm/dd/yy and I would like to change is that I can input a date like this 09 Mar 2019. Is there an easy way to change the date format? 日期的输入格式默认为mm / dd / yy,我想更改的是我可以输入一个类似2019年3月9日的日期。是否有一种简单的方法来更改日期格式? If not will I have to create a custom filter? 如果没有,我是否必须创建一个自定义过滤器? And if I do have a make a custom one, where can I find the implementation of the default one as reference. 如果我确实有一个自定义名称,则可以在其中找到默认名称的实现作为参考。

what I would like to modify 我想修改什么

you can't (currently) do it with the current datefilter because it internally uses <input type="date" /> (if using chrome, otherwise just a text field) which always takes the browsers locale as described in https://stackoverflow.com/a/9519493/885338 您无法(当前)使用当前的日期过滤器执行此操作,因为它内部使用了<input type="date" /> (如果使用的是chrome,否则仅是文本字段),它始终采用https://中所述的浏览器语言环境stackoverflow.com/a/9519493/885338

also described in https://github.com/ag-grid/ag-grid/issues/1029 (has also a vue.js example) https://github.com/ag-grid/ag-grid/issues/1029中也有描述(还有vue.js示例)

so you will either have to 所以你要么不得不

if you create a custom filter you could supply additional params like the desired date format via FilterParams 如果创建自定义过滤器,则可以通过FilterParams提供其他参数,例如所需的日期格式

The method init(params) takes a params object with the items listed below. 方法init(params)接受一个params对象,其中包含下列项目。 If the user provides params via the colDef.filterParams attribute, these will be additionally added to the params object, overriding items of the same name if a name clash exists. 如果用户通过colDef.filterParams属性提供参数,则这些参数将另外添加到params对象,如果存在名称冲突,则覆盖同名的项目。

taken from: https://www.ag-grid.com/javascript-grid-filter-component/#ifilter-params 摘自: https : //www.ag-grid.com/javascript-grid-filter-component/#ifilter-params

with that you could write a date filter that can work with different date formats (for example with using moment.js) by supplying the format via colDef.filterParams 这样,您可以编写一个日期过滤器,该过滤器可以通过colDef.filterParams提供格式,从而可以使用不同的日期格式(例如,使用moment.js)。

Ag-Grid has some nice examples for Dates -> https://www.ag-grid.com/javascript-grid-date-component/ Ag-Grid有一些不错的日期示例-> https://www.ag-grid.com/javascript-grid-date-component/

also see https://github.com/ag-grid/ag-grid/issues/1029#issuecomment-393546876 for this exact, still unresolved, issue and an example for vue.js which you may use as a starting point for your react based filter 另请参阅https://github.com/ag-grid/ag-grid/issues/1029#issuecomment-393546876,以了解此确切但仍未解决的问题以及vue.js的示例,您可以将其用作起点基于反应的过滤器

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

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