简体   繁体   English

Ag-Grid 在与下拉菜单交互期间保持自定义过滤器打开

[英]Ag-Grid keep custom filter open during interaction with dropdown

I have a custom filter component I'm giving Ag grid for each column.我有一个自定义过滤器组件,我为每列提供 Ag 网格。 The component contains a dropdown.该组件包含一个下拉列表。 When user selects an option from dropdown, the filter closes immediately on selection rather than staying open like it should.当用户从下拉列表中选择一个选项时,过滤器会在选择时立即关闭,而不是像它应该的那样保持打开状态。

How can I keep the filter component to stay open on selection of option from dropdown?如何在从下拉列表中选择选项时保持过滤器组件保持打开状态?

Reading the docs more, I found the answer here: https://www.ag-grid.com/javascript-data-grid/component-filter/#custom-filters-containing-a-popup-element更多地阅读文档,我在这里找到了答案: https : //www.ag-grid.com/javascript-data-grid/component-filter/#custom-filters- contains-a-popup-element

Custom Filters Containing a Popup Element Sometimes you will need to create custom components for your filters that also contain popup elements.包含弹出元素的自定义过滤器 有时您需要为同样包含弹出元素的过滤器创建自定义组件。 This is the case for Date Filter as it pops up a Date Picker.这是日期过滤器的情况,因为它会弹出一个日期选择器。 If the library you use anchors the popup element outside of the parent filter, then when you click on it the grid will think you clicked outside of the filter and hence close the column menu.如果您使用的库将弹出元素锚定在父过滤器之外,那么当您单击它时,网格会认为您在过滤器外部单击并因此关闭列菜单。

There are two ways you can get fix this problem:有两种方法可以解决此问题:

  • Add a mouse click listener to your floating element and set it to preventDefault().将鼠标单击侦听器添加到您的浮动元素并将其设置为 preventDefault()。 This way, the click event will not bubble up to the grid.这样,点击事件就不会冒泡到网格上。 This is the best solution, but you can only do this if you are writing the component yourself.这是最好的解决方案,但只有在您自己编写组件时才能这样做。

  • Add the ag-custom-component-popup CSS class to your floating element.将 ag-custom-component-popup CSS 类添加到您的浮动元素。 An example of this usage can be found here: Custom Date Component可以在此处找到此用法的示例:自定义日期组件

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

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