How to fix my Primefaces datatable pagination layout? - layout

I use primefaces to display a list in a datatable with pagination.
The layout for the Page DropDown is not correct.
Screenshot:
How can I set this layout?
It now stretches along the whole width of the table. This is not good.
<p:dataTable id="dataTable" value="#{bean.lazyModel}" var="item"
paginator="true"
rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink}
{LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,50,100"
lazy="true"
selectionMode="single"
selection="#{orderEntrySearchBacking.selected}"
rowKey="#{item.id}">
<f:facet name="header">
Patients
<p:commandButton id="toggler" type="button" value="Columns"
style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="dataTable" trigger="toggler" />
</f:facet>
<p:column>
<h:outputText value="#{item.name}"/>
</p:column>
<p:column>
<h:outputText value="#{item.date}"/>
</p:column>
....
This problem is related to the {RowsPerPageDropdown}, but I can't get the style correct. Help is appreciated.
That's all folks!

It looks like your <select> element has style width: 100%.
Inspect dropdown and find where style rule come from.
To fix it you should override this rule. One of the ways is to add following style rule to your .css file.
select.ui-paginator-rpp-options{
width:auto;
}

Related

Primefaces datatable unselect row on click with multiple selection

How to unselected a selected row on a dataTable primefaces using only a click, the same way that it work to select the row.
This is the code I am using to select and unselect at the moment, but the unselect needs to press the Ctrl or CMD (on mac) key.
<p:dataTable
value="#{adminiClubReconManager.bankMovementsFound}" var="movs"
style="width:90%;border: 0px;"
selection="#{adminiClubReconManager.selectedBankMovement}"
rowKey="#{movs.id}" editable="true" styleClass="rowStyle"
paginator="true" rowsPerPageTemplate="5,10,15" rows="10"
selectionMode="mutiple"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<p:ajax event="rowSelect"
listener="#{adminiClubReconManager.onBankRowSelect()}"
update="#form:reconMessages" />
<p:ajax event="rowUnselect"
listener="#{adminiClubReconManager.onBankRowUnselect()}"
update="#form:reconMessages" />
<p:column
style="background:transparent;border:0px;text-align:left">
<c:facet name="header">
<h:outputText
value="#{msg['admini.common.movement.recon.number']}" />
</c:facet>
<h:outputText value="#{movs.id}"
style="background:transparent;border:0px" />
</p:column>
...
</p:dataTable>
We've 2 possibilities for solve this issue.
First
Create commandButton and call primefaces method unselectAllRows();
<p:dataTable id="dataTableId" var="p" value="#{myBean.dataModel}" paginator="true" rows="50" paginatorPosition="bottom" emptyMessage="Empty results" rowKey="#{p.attribute}" selection="#{myBean.atributeList}" widgetVar="dataTableWidgetVar">`
<p:commandButton widgetVar="buttonClear" value="Clear selection" onclick="dataTableWidgetVar.unselectAllRows();"/>
</p:dataTable>
After the click you have the rows deselected
Second
Via ajaxEvent call primefaces method unselectAllRows();
<p:dataTable id="dataTableId" var="p" value="#{myBean.dataModel}" paginator="true" rows="50" paginatorPosition="bottom" emptyMessage="Empty results" rowKey="#{p.attribute}" selection="#{myBean.atributeList}" widgetVar="dataTableWidgetVar">`
<p:ajax event="page" update="dataTableId" oncomplete="dataTableWidgetVar.unselectAllRows();"/>
...
</p:dataTable>
In this case you selected the data of the first page when you click another page for example page 3, the ajax execute the method
UnselectAllRows (); And you clear you have selected.
For solve this i finded this material at primefaces forum in: https://forum.primefaces.org/viewtopic.php?f=3&t=24144

ui:repeat in datatable export as XLS (Primefaces)

I'm trying to export my datatable to Excel by using the following code:
<p:dataTable id="potentialDonorFileTable" var="potentialDonorFile"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
value="#{analyseBackingBean.allPotentialDonorFiles}" rows="30"
paginator="true" lazy="true">
<f:facet name="{Exporters}">
<h:commandLink>
<h:outputText id="downloadAsXls" value="download"/>
<p:dataExporter type="xls" target="potentialDonorFileTable" fileName="potontial-donor-files"/>
</h:commandLink>
</f:facet>
<p:column headerText="#{msgs['registration.number']}">
<h:outputText value="#{potentialDonorFile.registrationNumber}"/>
</p:column>
</p:dataTable>
and this is working correctly. However, now I need to display a list of items in a certain column and also export that list to excel.
<p:column headerText="#{msgs['reason']}">
<ui:repeat value="#{potentialDonorFile.list}"
var="item">
<h:outputText
value="#{msgs['enum.translation.'.concat(item)]}"/>
</ui:repeat>
</p:column>
The values are correctly displayed, but when I'm exporting this datatable to excel then I'm getting the following cell: "com.sun.faces.facelets.component.UIRepeat#6063d832". Is there any way to work around this using primefaces 5.2?

Primefaces datatable header searchbox breaks table layout

i have a realy strange behavior if i place components inside a datatable header.
Code for the Table
<p:dataTable id="groupTable" var="group" value="#{profile.user.groups}"
widgetVar="groupTable" rows="10" paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,20,40,80"
emptyMessage="Keine Einträge mit den gewünschten Kriterien gefunden"
filteredValue="#{groupView.filteredGroups}" sortMode="multiple"
resizableColumns="true" liveResize="true">
<f:facet name="header">
<h:outputText value="Zugeordnete Gruppen" />
<p:outputPanel style="float:left;">
<p:inputText id="globalFilter" onkeyup="PF('groupTable').filter()" style="width:150px;" placeholder="Suche"/>
</p:outputPanel>
</f:facet>
<p:column headerText="Gruppenname" filterBy="#{group.name}"
sortBy="#{group.name}" filterMatchMode="contains"
filterStyle="display:none" style="width:150px">
<h:outputText value="#{group.name}"/>
</p:column>
<p:column headerText="Beschreibung" filterBy="#{group.beschreibung}"
sortBy="#{group.beschreibung}" filterMatchMode="contains"
filterStyle="display:none">
<h:outputText value="#{group.beschreibung}"/>
</p:column>
</p:dataTable>
you can find the generated HTML here jsfiddle
On the Page itself it looks like this:
So what is the problem with the code? why does the serach box destroy the table layout?
Okay i found it. Maybe it will help someday another facing the same Problem.
The Searchbox is to big in line with the Text. If i change the inputtext size and set the outputpanel inline it looks like it was intended.
<f:facet name="header">
<h:outputText value="Zugeordnete Gruppen" />
<p:outputPanel style="display:inline">
<p:inputText id="globalFilter" onkeyup="PF('groupTable').filter()" style="width:150px;height:10px;float:left" placeholder="Suche"/>
</p:outputPanel>
</f:facet>

Cannot associate an action on a primefaces lazy loading table

I've been trying to make use of primefaces lazy loading datatable. Without the lazy loading, the method delete(trans) gets called but not same with the lazy. Please, can someone tell me why the delete(trans) is never called when clicked. I've been on it all day (I tried with primefaces 4.x and 5.x)
<h:form>
<p:dataTable value="#{transactionView.transactions}" var="trans"
paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" lazy="true">
<p:column headerText="#{messages.trans_date}" width="100">
<h:outputText value="#{trans.transDate}">
<f:convertDateTime pattern="#{messages.date_pattern2}"/>
</h:outputText>
</p:column>
<p:column headerText="#{messages.description}">
<h:outputText value="#{trans.description}"/>
</p:column>
<p:column>
<p:commandLink value="X" style="color: red" update="#form" ajax="true"
action="#{transactionView.delete(trans)}"/>
</p:column>
</p:dataTable>
</h:form>

How to clean <p:dataTable> globalFilter field?

I have the following requirement:
In case the user push one of the paginator buttons and there is a value in the globalFilter inputText then the value should be deleted.
This is the table (lazy loading):
<p:dataTable id="osTable"
var="os"
value="#{bean.lazyModel}"
selection="#{bean.selectedObjectSet}"
selectionMode="single"
rowKey="#{os.ID}"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
rows="10"
widgetVar="table">
<f:facet name="header">
<p:outputPanel style="float: right">
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter"
value="#{bean.find}"
onkeypress="if (event.keyCode == 13) {table.filter()}"
style="width:150px">
</p:inputText>
</p:outputPanel>
</f:facet>
I guess I need to do that via javascript but I don’t know how to implement this kind of functionality.
try this :
<p:ajax event="page" oncomplete="jQuery('#yourFormID\\:yourDataTableID\\:globalFilter').val('')"/>
this should clean the filter on pagination complete....

Resources