Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces Datatable within Tabview - initial sort on second tab doesnt work

I have a tabView where each tab contains a datatable. I have it set up like so

<p:tabView id="tabView" styleClass="manage-tab-view" prependId="false" 
        activeIndex="#{managementTabBean.activeIndex}" dynamic="true" cache="false">
<p:tab id="users" title="#{msg['TeamManagement.Tabs.Users']}" >
            <ui:include src="tab1.xhtml" />
        </p:tab>
<p:tab id="athletes" title="#{msg['TeamManagement.Tabs.Athletes']}">
            <ui:include src="tab2.xhtml" />
</p:tab>
</p:tabView>

Within each tab I am trying to show a datatable. Right now I have it set up like this:

Tab1:

<h:form id="userProfileViewForm" prependId="false">
    <p:dataTable var="userProfile" value="#{userProfileListBean.objects}"
        id="userProfilesTable" sortBy = "#{userProfile.lastName}" sortFunction = "#{userProfileListBean.sortUserLastName}" sortOrder = "ascending" lazy="true">

        <p:column sortBy="#{userProfile.lastName}" sortFunction = "#{userProfileListBean.sortUserLastName}" id="userName">
p:commandLink>
             <p:commandLink rendered="#{!appContextBean.isCWContext()}"
                    onclick="window.location.href='userBS.xhtml?id=#{userProfile.id}'">
                    <div class="clickable-cell">
                        <h:outputText
                        value="#{userProfile.firstName} #{userProfile.lastName}" />
                    </div>
            </p:commandLink>
        </p:column>

...more columns...

Tab2: Similar DataTable

<p:dataTable var="athlete" value="#{athleteListBean.objects}"
        tableStyle="width:auto" sortBy="#{athlete.getDisplayName()}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athletesTable" 
        sortOrder="#{athleteListBean.getListSortOrderDesc()}" lazy="true" paginator="true" rows="15" paginatorPosition="bottom"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}">

        <p:column sortBy="#{athlete.getDisplayName()}" sortFunction = "#{athleteListBean.sortAthleteDisplayName}" id="athleteColumn">
<h:outputText styleClass="athlete-listing athlete-name" value="#{athlete.firstInitial} #{athlete.lastName}" />
</p:column>

As you can see I have a custom initial sorting function set up for both datatables.

For some reason the first tab sorting function gets called, and the second tab sorting function does not. After I swapped the tabs in the tabview, tab2 sorting function gets called, but tab1 doesnt.

Basically the initial sorting function only gets called on the datatable of the first tab, based on the order of tabs in the tab view. Can anyone tell me why this is happening?

Thank you for your help.

like image 574
Matt Kagan Avatar asked Aug 23 '26 15:08

Matt Kagan


1 Answers

I had a similar problem, in my case on the second tab had a p:dataTable with p:columnToggler, and clicking on the button to hide or display columns are displayed in black and could not remove the columns.

The solution I found was to add on event "tabChange" in p:ajax inside p:TabView

In this way the problem was solved and I already work properly on p:columnToggler.

Maybe you serve to the problem you have with the order of the p:dataTable.

Here I put my code:

<p:tabView effect="fade" effectDuration="fast"  prependId="false">
    <p:ajax event="tabChange" update="@this"/>
    <p:tab title="#{text['liquidacionForm.tabDatosLiq']}">
       <ui:include src="/datosLiquidacion.xhtml"></ui:include>
     </p:tab>
    <p:tab title="#{text['liquidacionForm.tabEstanciasLiq']}">
       <ui:include src="/estanciasLiquidadas.xhtml"></ui:include>
   </p:tab>
</p:tabView>
like image 72
nokiajavi Avatar answered Aug 25 '26 04:08

nokiajavi