primefaces:datatable: custom filter: "contains" instead of "beginning" - primefaces

By default, primeface filter dataTable's rows, by finding rows that columns begins with the string entered in the search area.
How do I filter the DataTable rows that the column contains (not begins with) the string entered in the search area?

You can do this using filterMatchMode attribute on p:column of the dataTable. A very good example can be found on PrimeFaces showcase.
So if we take the above mentioned example, you could have roughly something like this:
<p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
filteredValue="#{dtFilterView.filteredCars}">
<p:column filterBy="#{car.id}" headerText="Id" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
The attribute filterMatchMode accepts values such as contains, endsWith, startsWith, exact...

Related

Expand a specific row of a p:dataTable

I have a screen where I have a list of items and an expansion button left. In the filter if the user enter with a specific information it will bring the same entire list BUT I need to expand the specific row.
<p:rowExpansion>
<p:dataTable var="inventoryPartsItems"
value="#{partnerInventory.getInventoryItems(inventoryPart)}"
emptyMessage="#{msgs.common_no_registries}" id="tableItems">
<p:column style="width:16px">
<p:rowToggler
rendered="#{inventoryPartsItems.sapOperation != null}" />
</p:column>

Primefaces dataTable populate (search) doesn't work well after filtering

I have a Primefaces dataTable like this in a <h:form> block:
<p:dataTable id="basicDT" var="partyDB" value="#{mbRechercheAbonne.listPartyDB}"
paginator="true"
emptyMessage="Aucun abonné ne correspond aux critères"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
rows="25"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100"
currentPageReportTemplate="{startRecord} - {endRecord} sur {totalRecords} résultats"
filteredValue="#{mbRechercheAbonne.filteredListPartyDB}">
and a search button that populates the dataTable using a #ViewScoped bean that updates the value of listPartyDB when rechercheAbonne() is called:
<p:commandButton value="Rechercher" update="display :consultform:basicDT" icon="ui-icon-check"
actionListener="#{mbRechercheAbonne.rechercheAbonne()}" onstart="startRecherche()" oncomplete="stopRecherche()"/>
Searching multiple times works, the dataTable's content changes like expected.
However, when using filtering and then removing the filter (i.e. adding a letter in a filter field above a column and then removing that letter), the search no longer works. I found that the search does actually work, but I need to apply a filter again (and remove it to have the unfiltered list) to see the result of the new search.
Explaining with pictures :
Searching for "test":
Searching for "abc" right after, works as intended:
Searching for test again, filtering one column, works as intended:
Removing the filter (going back to pic 1), and then searching for "abc". Does not work:
Applying a filter again does it on the "abc" search that wasn't showing originally - removing the filter shows what the last search should have shown.
Thanks for your help.

Primefaces dataTable iterate list inside list by index

In my JSF example I am getting a list which contains two lists:
One for result returned from DB and another containing list of column header from DB.
In the first list(containing result) has row data per index.
e.g. **
transaction.transactionsList[0][1]
contain one row data in below code snippet:
<p:dataTable value="#{transaction.transactionsList[0]}" var="tran">
<p:columns value="#{transaction.transactionsList[1]}" var="column"
sortBy="#{tran[column.property]}">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{tran[column.property]}" />
</p:columns>
</p:dataTable>
Please advise how to iterate based on length of list containing data and based on index over nested list, like:
transaction.transactionsList[0][i]

Primefaces calendar : Not able to format the date

Updated : I have used primefaces calendar to show dates. It's default format is mm/dd/yy but for other locale like german it is dd.mm.yy. If I specify the format for english for example dd/MM/yyyy then it shows correct format for english but then on changing language to german it shows again dd/MM/yyyy instead of dd.MM.yyyy
I have tried this :
<p:calendar id="createdDateToDK"
value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
mode="popup" navigator="true" pattern="dd/MM/yyyy>
<f:converter converterId="messages.convertors.DateConvertor" />
</p:calendar>
I have tried below also:
<p:calendar id="createdDateToDK"
value="#{messagesDefaultKeys.createdDateTo}" showOn="button"
mode="popup" navigator="true">
<f:convertDateTime for="createdDateToDK" pattern="dd/MM/yyyy"></f:convertDateTime>
</p:calendar>
I am using primefaces3.5 jar and JSF2.0 .
I do not want to add another calendar component just for another language . Please note that this happens only when I specify the format for calendar else while it works well with different locales.
No need to use a converter for dates, calendar comes with an attribute called pattern, you can use it to change the pattern of dates, for exemple <p:calendar pattern="dd.MM.yyyy HH:mm" /> this will show 21.02.2017 15:42, you can change the pattern to separate the date however you like using dots, slach or any character

Datatable issues when presenting dynamic columns

I've got a NULLPointerException.
I have iplemented an object called Workhours, which has list of Hours and a workday (enum value).
Now, I have a list
I would like to present it in a datatable with the workday (enum) name as a row, and the hours as columns. Now, this is what I tried:
<p:dataTable id="dtWorkHours" var="workhour" value="#{uploadImagesPage.lwh}" >
<p:column>
<f:facet name="header">
<h:outputText value="Days"></h:outputText>
</f:facet>
<h:outputText value="#{workhour.workday}"></h:outputText>
</p:column>
<p:columns value="#{workhour.luh}" var="columnUntilHours" columnIndexVar="index">
<f:facet name="header">
#{columnUntilHours.untilhours}
</f:facet>
<h:selectBooleanCheckbox value="#{columnUntilHours.checked}" >
</h:selectBooleanCheckbox>
</p:columns>
</p:dataTable>
I checked initialization of WorkHours object and it seems everythings's in place. Is there any reason why I p:columns doesn't work (and when I put it out, the workday presentation as row works)?
Thanks in Advance !
I do not believe it is possible to mix dynamic and static columns within a single Primefaces dataTable. You must choose one method or the other.
If you wish to show the workday column within this then perhaps you can create create a viewable composite entity type that combines properties of both workday and the row entities into a single type. Workday can be just another object that always exist in your dynamic column collection.