cell merge in datatable at primefaces

空扰寡人 提交于 2019-12-11 04:07:11

问题


I am new to primefaces. I have one datatable in my application. In that for 3 columns i need to merge some rows. That row count will be generated dynamically based on the data. If I tried to use rowspan in that particular column tag, it additionally created blank cells and the total datatable format is changed. How to do merge that datarows in primefaces. For reference, I am attaching the design and code.

Xhtml code:

    <f:facet name="header">
        <h:outputText value="Date"></h:outputText>
    </f:facet>  
        <h:outputText value="#{step2table.rs2_date}" />

</p:column>

<p:column style="font-size:12px;width:73px;" >
    <f:facet name="header">
        <h:outputText value="Slot"></h:outputText>
    </f:facet>  
        <h:outputText value="#{step2table.rs2_slot}" />
</p:column>

<p:column style="font-size:12px;width:73px;" >
    <f:facet name="header">
        <h:outputText value="Number of Resources Required"></h:outputText>
    </f:facet>  
        <h:outputText value="#{step2table.rs2_noresources}" />
</p:column>

<p:column headerText="Select" id="hSelect" style="font-size:12px;width:60px;">

    <p:selectBooleanCheckbox id="Booleanchkbox" onclick="{dtstep2_tab1.select='true'}" >  
        <p:ajax listener="#{dtstep2_tab1.UpdateStatus}" update="panel1" />

    </p:selectBooleanCheckbox>
</p:column>

<p:column style="font-size:12px;width:70px;">
    <f:facet name="header">
        <h:outputText value="Employee Name"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_empname}"  />
</p:column>

<p:column style="font-size:12px;width:120px;">
    <f:facet name="header">
        <h:outputText value="Contact Details"></h:outputText>
    </f:facet>
    <h:outputText value="#{step2table.rs2_contactdet}" />
</p:column>

<p:column style="font-size:12px;width:70px;">
    <f:facet name="header">
        <h:outputText value="Worked Hrs to Date"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_totworkhours}" />
</p:column>

<p:column style="font-size:12px;width:50px;">
    <f:facet name="header">
        <h:outputText value="Agency Recruited"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_recruitmode}"  />
</p:column>

<p:column style="font-size:12px;width:70px;">
    <f:facet name="header">
        <h:outputText value="Priority"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_priority}"/>
</p:column>

<p:column style="font-size:12px;width:90px;">
    <f:facet name="header">
        <h:outputText value="Type of Skill"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_skilltype}"  />
</p:column>

<p:column style="font-size:12px;width:120px;">
    <f:facet name="header">
        <h:outputText value="Restriction"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_restriction}" />
</p:column>

<p:column style="font-size:12px;width:150px;">
    <f:facet name="header">
        <h:outputText value="Rest. Details"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_restdet}"  />
</p:column>

<p:column style="font-size:12px;width:70px;">
    <f:facet name="header">
        <h:outputText value="B2B Days"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_b2bdays}"  />
</p:column>

<p:column style="font-size:12px;width:70px;">
    <f:facet name="header">
        <h:outputText value="B2B Hrs"></h:outputText>
    </f:facet>
        <h:outputText value="#{step2table.rs2_b2bhrs}" />
</p:column>

<p:column headerText="Status" id="hStatus" style="font-size:12px;width:100px;">
    <h:selectOneMenu id="cbo" value="#{step2table.rs2_status}" >
        <f:selectItem itemLabel="Confirmed" itemValue="Confirmed"></f:selectItem>
        <f:selectItem itemLabel="Selected" itemValue="Selected"></f:selectItem>
        <f:selectItem itemLabel="Rejected" itemValue="Rejected"></f:selectItem>

    </h:selectOneMenu>
</p:column>

<p:column style="font-size:12px;width:150px;">
    <f:facet name="header">
        <h:outputText value="Comments"></h:outputText>
    </f:facet>
        <h:inputText value="#{step2table.rs2_comments}" rendered="#{dtstep2_tab1.editable}"/>
</p:column>

Need to merge first three columns "date, Slot, and No of Resources Required" based on the employee column data. Guide me on this. Thanks in advance.


回答1:


You can use p:summaryRow tag in p:dataTable. Example:

<h:form>
    <p:dataTable var="car" value="#{dtSummaryRowView.cars}" sortBy="#{car.brand}">
        <p:column headerText="Id" sortBy="#{car.id}">
            <h:outputText value="#{car.id}" />
        </p:column>
        <p:column headerText="Year" sortBy="#{car.year}">
            <h:outputText value="#{car.year}" />
        </p:column>
        <p:column headerText="Brand" sortBy="#{car.brand}">
            <h:outputText value="#{car.brand}" />
        </p:column>
        <p:column headerText="Color" sortBy="#{car.color}">
            <h:outputText value="#{car.color}" />
        </p:column>
        <p:summaryRow>
            <p:column colspan="3" style="text-align:right">
                <h:outputText value="Total:" />
            </p:column>
            <p:column>
                <h:outputText value="#{dtSummaryRowView.randomPrice}">
                    <f:convertNumber type="currency" currencySymbol="$" />
                </h:outputText>
            </p:column>
        </p:summaryRow>
    </p:dataTable>
</h:form>

For more information, see the primefaces showcase link: http://www.primefaces.org/showcase/ui/data/datatable/summaryRow.xhtml




回答2:


This is simply not possible in the datatable.




回答3:


<p:column width="440">
    <p:panelGrid rendered="#{someCondition}">
        <f:facet name="header">
            <p:row>                             
                <p:column width="80"><h:outputText value="#{msg.isin}" /></p:column>
                <p:column width="80"><h:outputText value="#{msg.wkn}" /></p:column>
                <p:column width="200"><h:outputText value="#{msg.name}" /></p:column>
                <p:column width="80"><h:outputText value="#{msg.amount}" /></p:column>
            </p:row>
        </f:facet>
        <p:row>                             
            <p:column><h:outputText value="#{savingsPlanPosition.isin}" /></p:column>
            <p:column><h:outputText value="#{savingsPlanPosition.wkn}" /></p:column>
            <p:column><h:outputText value="#{savingsPlanPosition.name}" /></p:column>
            <p:column><h:outputText value="#{savingsPlanPosition.amount}" /></p:column>
        </p:row>
    </p:panelGrid>
    <p:panelGrid rendered="#{!someCondition}">
        <h:link id="savingsPlanPositionDetails${rowIndex}"
            title="#{msg.assign_etf}"
            outcome="portfolioPositionDetail">
            <f:param name="portfolioId"
                value="#{savingsPlanController.portfolioId}"></f:param>
            <f:param name="portfolioPositionId"
                value="#{savingsPlanPosition.portfolioPositionId}"></f:param>
            <f:param name="from"
                value="savingsPlan"></f:param>
            <h:outputText value="#{msg.assign_etf}"/>
        </h:link>
    </p:panelGrid>
</p:column>


来源:https://stackoverflow.com/questions/31109438/cell-merge-in-datatable-at-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!