简体   繁体   English

如何让自定义选择浮动过滤器成为 ag-grid angular 中列的全宽

[英]How to get custom select floating filter to be full width of column in ag-grid angular

I'm cannot seem to get a custom floating filter component to be the full width of a column using ag-grid in angular 8. I have the follow template and css for my component:我似乎无法使用 angular 8 中的 ag-grid 使自定义浮动过滤器组件成为列的全宽。我的组件具有以下模板和 css:

@Component({
    template: `
        <select [(ngModel)]="selectedOption" (ngModelChange)="valueChanged()">
            <option value="all">All</option>
            <option value="true">True</option>
            <option value="false">False</option>
        </select>`,
    styles: ['select {width: 100%;}']
})

when I look at the elements in chrome it appears that the filter component is not inheriting the width of its parent.当我查看 chrome 中的元素时,似乎过滤器组件没有继承其父级的宽度。 does ag-grid provide a simple way to do this or is there another way using css? ag-grid 是否提供了一种简单的方法来做到这一点,还是有另一种使用 css 的方法?

I ended up having to query my input element from from the dom then I got the parent element of my input element and set the width to '100%' and that worked for me.我最终不得不从 dom 查询我的输入元素,然后我得到了输入元素的父元素并将宽度设置为“100%”,这对我有用。

So in your 'onParentModelChanged' function add the new line below:所以在你的 'onParentModelChanged' 函数中添加下面的新行:

onParentModelChanged(parentModel: any) {
       document.querySelector('#YOUR_FLOATING_FILTER_INPUT_ID').parentElement.style.width = '100%'; // <- This is the new line
       // When the filter is empty we will receive a null value here
       if (!parentModel) {
           this.currentValue = null;
       } else {
           this.currentValue = parentModel.filter;
       }
   }

Don't forget to add the id to the input element.不要忘记将 id 添加到输入元素。 I hope there's a better way to do this but for now that's what I'm going with.我希望有更好的方法来做到这一点,但现在这就是我要做的。

You could also add a flag to check if its already been set so you don't keep resetting the value.您还可以添加一个标志来检查它是否已经设置,这样您就不会一直重置该值。

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

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