p:dataTable 在选择其他过滤器时修改下拉过滤器
p:dataTable modify drop down filter on selection of other filter
我正在使用 primefaces
带过滤器的数据表。在过滤器中,我有两个下拉 select 框。我想在 select 之后修改第二个下拉框。
这是我的代码:
<p:dataTable id="stockTable1" widgetVar="stockTable" var="stock" value="#{stockBean.stockList}" filteredValue="#{stockBean.filteredStocks}" paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,20, 50">
<p:column headerText="Product Id" sortBy="#{stock.name}" filterBy="#{stock.name}">
<h:outputText value="#{stock.name}" />
</p:column>
<p:column headerText="Category" sortBy="#{stock.categoryId}" filterBy="#{stock.categoryId}" filterMatchMode="exact">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('stockTable').filter()" value="#{stockBean.selectedCategory}">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{stockBean.categoryNames}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{stock.categoryId}" />
</p:column>
<p:column headerText="Sub Category" sortBy="#{stock.subCategoryId}" filterBy="#{stock.subCategoryId}" filterMatchMode="exact" >
<f:facet name="filter">
<p:selectOneMenu onchange="PF('stockTable').filter()" immediate="true" id="subChange">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{stockBean.subcategoryNames}" />
</p:selectOneMenu>
</f:facet>
<h:outputText id="stockDescription" value="#{stock.subCategoryId}" />
</p:column>
<p:column headerText="Last Updated" sortBy="#{stock.updatedTS}" >
<h:outputText value="#{stock.updatedTS}" >
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
</h:outputText>
</p:column>
</p:dataTable>
我想修改select类别后的子类别下拉框。
您可以将 p:ajax
事件附加到第一个 p:selectOneMenu
:
<p:selectOneMenu onchange="PF('stockTable').filter()"
value="#{stockBean.selectedCategory}">
<!-- ... -->
<p:ajax event="change"
process="stockTable1"
update="stockTable1"
partialSubmit="true"
listener="#{stockBean.changeSubcategoryNames}"/>
例如,您可以在新方法 stockBean.changeSubcategoryNames
中调整 subChange
的值。
我正在使用 primefaces
带过滤器的数据表。在过滤器中,我有两个下拉 select 框。我想在 select 之后修改第二个下拉框。
这是我的代码:
<p:dataTable id="stockTable1" widgetVar="stockTable" var="stock" value="#{stockBean.stockList}" filteredValue="#{stockBean.filteredStocks}" paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,20, 50">
<p:column headerText="Product Id" sortBy="#{stock.name}" filterBy="#{stock.name}">
<h:outputText value="#{stock.name}" />
</p:column>
<p:column headerText="Category" sortBy="#{stock.categoryId}" filterBy="#{stock.categoryId}" filterMatchMode="exact">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('stockTable').filter()" value="#{stockBean.selectedCategory}">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{stockBean.categoryNames}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{stock.categoryId}" />
</p:column>
<p:column headerText="Sub Category" sortBy="#{stock.subCategoryId}" filterBy="#{stock.subCategoryId}" filterMatchMode="exact" >
<f:facet name="filter">
<p:selectOneMenu onchange="PF('stockTable').filter()" immediate="true" id="subChange">
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{stockBean.subcategoryNames}" />
</p:selectOneMenu>
</f:facet>
<h:outputText id="stockDescription" value="#{stock.subCategoryId}" />
</p:column>
<p:column headerText="Last Updated" sortBy="#{stock.updatedTS}" >
<h:outputText value="#{stock.updatedTS}" >
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
</h:outputText>
</p:column>
</p:dataTable>
我想修改select类别后的子类别下拉框。
您可以将 p:ajax
事件附加到第一个 p:selectOneMenu
:
<p:selectOneMenu onchange="PF('stockTable').filter()"
value="#{stockBean.selectedCategory}">
<!-- ... -->
<p:ajax event="change"
process="stockTable1"
update="stockTable1"
partialSubmit="true"
listener="#{stockBean.changeSubcategoryNames}"/>
例如,您可以在新方法 stockBean.changeSubcategoryNames
中调整 subChange
的值。