如何修改PrimeReact表格中的筛选图标功能

huangapple go评论69阅读模式
英文:

How to modify filter icon functionality in table in PrimeReact

问题

我有一个基于Prime React的表格和一个多选下拉筛选器,用于其中一个列,就像"Agent"列一样(链接)。

当我们点击筛选图标时,"Agent Picker"多选下拉框将显示。然后,我们需要再次点击下拉框以查看选项并选择进行筛选结果。

但我的要求是,一旦我们点击筛选图标,多选下拉框应该默认显示选项,减少用户的一次点击。这是否可以实现?请提供任何想法/参考链接。谢谢。

我想要实现这样的效果:

如何修改PrimeReact表格中的筛选图标功能

这是我尝试过的内容: https://codesandbox.io/s/primereact-demo-forked-c6kw73?file=/src/App.js

谢谢。

英文:

I have a prime react table and a multiselect dropdown filter for one of the column like "Agent" column (Link)

When we click on the filter icon, "Agent Picker" multiselect dropdown will display. Then we again need to click on the dropdown to see the options and choose for filtering the results.

But my requirement is, as soon as we click on filter icon, the multiselect should display default options open, reducing one click for the user. Is this achievable? Please suggest any idea/reference link. Thanks.

I wanna achieve like this:

如何修改PrimeReact表格中的筛选图标功能

Here is what I tried: https://codesandbox.io/s/primereact-demo-forked-c6kw73?file=/src/App.js

Thanks.

答案1

得分: 1

我修复了你的示例:

const UserNameFilterTemplate = (options) => {
    setTimeout(() => {
        multiselectRef && multiselectRef.current && multiselectRef.current.show();
    }, 500);

    return (
        <MultiSelect
            ref={multiselectRef}
            value={options.value}
            options={usernames}
            itemTemplate={userNameItemTemplate}
            onChange={(e) => options.filterCallback(e.value)}
            optionLabel="name"
            optionValue="name"
            placeholder="Any"
            autoFocus
            className="p-column-filter"
        />
    );
};
英文:

I fixed your example:

const UserNameFilterTemplate = (options) =&gt; {
    setTimeout(() =&gt; {
      multiselectRef &amp;&amp; multiselectRef.current &amp;&amp; multiselectRef.current.show();
    }, 500);

    return (
      &lt;MultiSelect
        ref={multiselectRef}
        value={options.value}
        options={usernames}
        itemTemplate={userNameItemTemplate}
        onChange={(e) =&gt; options.filterCallback(e.value)}
        optionLabel=&quot;name&quot;
        optionValue=&quot;name&quot;
        placeholder=&quot;Any&quot;
        autoFocus
        className=&quot;p-column-filter&quot;
      /&gt;
    );
  };

https://codesandbox.io/s/primereact-demo-forked-56mh8j

You were missing optionValue=&quot;name&quot; so it was making the whole object the value instead of the String value of the username selected.

huangapple
  • 本文由 发表于 2023年6月22日 19:32:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76531435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定