【问题标题】:primefaces global filter with commandlink使用 commandlink 的 primefaces 全局过滤器
【发布时间】:2013-01-04 03:08:06
【问题描述】:

好的。所以我正在尝试使用commandLinks 实现一个全局过滤器。这个想法是有一个 commandLinks 的字母表,然后用户可以使用它而不是输入字母。

到目前为止,我已经对列进行了过滤(一旦 commandLinks 工作,将添加 filterStyle none)。

使用 chromes 调试工具(ctrl-shift+i),点击命令链接,我可以看到数据表刷新列表。但是,它不会过滤任何内容。

我一直在使用 primefaces 展示,这个 stack overflow post 是我的代码的基础,如下所示:

 <p:dataTable id="availableSpecies" var="species" value="#{bbWizardBean.speciesPaletteList}"
                                    emptyMessage="Add First Species" dynamic="true"
                                    width="120"
                                    widgetVar="speciesPaletteVar"
                                    scrollHeight="250" scrollRows="20" scrollable="true"
                                    styleClass="width-fix-spcPal-ie" style="width:150px; margin-left: auto; margin-right: auto;"
                                    filteredValue="bbWizardBean.speciesPaletteListFilter">

        <f:facet name="header">
                            <h:outputText value="Species Palette" />
                            <p:commandLink id="globalFilter" value="A" onclick="$('speciesColumn_filter').val('A'),speciesPaletteVar.filter()"/>
        </f:facet>
        <p:column filterBy="#{species.speciesName}"
                                    headerText="Species" style="font-size:13px;" id="speciesColumn">
            <h:outputText id="dragIcon" value="#{species.speciesNameSmall}" style="font-size:11px; background-color:silver; cursor:move;"/>
            <h:outputText id="dragIconTooltip" value="..." title="Full Name: #{species.speciesName}" rendered="#{species.speciesNameLength > 10}"/>
            <p:tooltip for="dragIconTooltip" />

                            <p:draggable for="dragIcon" revert="true" />
        </p:column>

我删除了表格的其余部分以使代码库更小。我想我搞砸了我应该设置的值,但我不太确定如何设置。任何帮助,将不胜感激!第一篇文章,所以任何清理问题的建议都值得赞赏;)

【问题讨论】:

    标签: primefaces


    【解决方案1】:

    好的,所以由于某种原因(就像我想的那样),过滤器的 val 设置无法正常工作。出于某种原因,您需要在 : 之前添加两个 \。如果有人知道,那就太棒了,但正确的代码是:

    <p:commandLink id="globalFilter" value="A" onclick="$('#positiveRegulationForm\\:availableSpecies\\:speciesColumn_filter').val('A'),speciesPaletteVar.filter()"/>
    

    在哪里 positiveRegulationForm 是顶层表单 availableSpecies 是数据表名称 speciesColumn_filter 是列speciesColumn的过滤器

    真的很好奇为什么需要两个正斜杠

    【讨论】:

    • 第一个 ` is to escape the :` 否则将被解释为 jQuery 选择器和第二个 ` is to escape the first ` ...
    • 噢噢噢,好的。我以前从未使用过 jQuery 选择器。谢谢!想知道我实际上在逃避什么:p
    猜你喜欢
    • 2012-05-28
    • 2013-01-29
    • 1970-01-01
    • 2013-05-22
    • 2016-08-19
    • 1970-01-01
    • 2016-10-28
    • 2014-09-20
    • 2019-06-11
    相关资源
    最近更新 更多