following p:dataTable with dynamic columns:
<p:dataTable value="#{searchMaskBL.getSearchMaskDescription().getRows()}" var="curRow">
<p:columns value="#{curRow.getColumns()}" var="curColumn">
<h:outputLabel value="#{curColumn.label} #{curColumn.colonOnRightSide ? ':' : ''}" for="colInputTextId" />
<h:inputText id="colInputTextId" value="" />
</p:columns>
</p:dataTable>
The iteration over the rows defined with #{searchMaskBL.getSearchMaskDescription().getRows()} works, but #{curRow.getColumns()} is never called. Also curRow.columns does not work. What' wrong? The ui model has rows and columns.
Regards
Oliver
You can't have the columns value attribute iterate over the current row...
According to the columns example in the PF showcase, you should it like this (but adapt it to your scenario:
<p:dataTable id="cars" var="car" value="#{dtColumnsView.cars}" widgetVar="carsTable" filteredValue="#{dtColumnsView.filteredCars}">
<p:columns value="#{dtColumnsView.columns}" var="column" columnIndexVar="colIndex" sortBy="#{car[column.property]}" filterBy="#{car[column.property]}">
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{car[column.property]}" />
</p:columns>
</p:dataTable>
Where you populate a columns model and iterate over that in the value attribute of the colums tag
Related
After filtering of primefaces 'tasksDataTable', the 'number of records' does not update.
For example before filtering number of records is 45, and by filtering table i get 3 records as result. But 'number of records' is already 45 (i expect to show 3 for 'number of records' after filtering).
How can i handle it?
<p:dataTable var="recordEntity"
id="rulesDataTable"
widgetVar="rulesDataTable"
value="#{bossCartable.tasksDataTable}"
paginator="true"
paginatorAlwaysVisible="false"
rows="#{paginationModel.rows}"
paginatorTemplate="#{paginationModel.paginationTemplate}"
rowsPerPageTemplate="#{paginationModel.rowsPerPageTemplate}"
currentPageReportTemplate="#{paginationModel.currentPageReportTemplate}"
selectionMode="single"
selection="#{bossCartable.selectedRuleRow}"
rowIndexVar="rowIndex"
sortBy="#{recordEntity.id}"
emptyMessage="No record found!"
rowKey="#{recordEntity.id}"
resizableColumns="true"
>
<f:facet name="header">
<div class="row align-content-center">
Tasks
<h:outputLabel value="number of records: #{bossCartable.tasksDataTable.size()}"/>
</div>
</f:facet>
<p:column headerText="id" width="5%" filterMatchMode="contains"
filterBy="#{recordEntity.id}" sortBy="#{recordEntity.id}" sortable="true">
<h:outputText value="#{recordEntity.id}"/>
</p:column>
<p:column headerText="description" filterMatchMode="contains"
filterBy="#{recordEntity.description}">
<h:outputText value="#{recordEntity.description}"/>
</p:column>
<p:column headerText="startDate" width="8%" filterMatchMode="contains"
filterBy="#{recordEntity.startDate}">
<h:outputText value="#{recordEntity.startDate}"/>
</p:column>
<p:column headerText="endDate" width="8%" filterMatchMode="contains"
filterBy="#{recordEntity.endDate}">
<h:outputText value="#{recordEntity.endDate}"/>
</p:column>
</p:dataTable>
With non lazy loading the filtered value can be stored using the filteredValue attribute. See: https://primefaces.github.io/primefaces/8_0/#/components/datatable
This will allow you to use:
<p:dataTable value="#{bossCartable.tasksDataTable}"
filteredValue="#{bossCartable.tasksFiltered}"
...>
</p:dataTable>
and
#{bossCartable.tasksFiltered.size()}
where tasksFiltered should point to a writable List.
Also, your header facet will not be updated by magic, you should put you text in a component and update that component on the filter event of the data table.
See also:
Primefaces datatable update in f:facet name="header" not working
https://primefaces.github.io/primefaces/8_0/#/components/datatable?id=ajax-behavior-events
When using autoComplete and columnToggler within a dataTable, I get a broken column-list in the column toggler.
That means, the column-list doesn't show the column-names but some javascript code instead (for each column).
Here is an example:
<p:commandButton id="showColsButton" type="button" value="Show Columns" />
<p:columnToggler datasource="myDataTable" trigger="showColsButton" />
<p:dataTable id="myDataTable" var="row" ...>
<p:column sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
</p:dataTable>
Is this a bug or is there any solution for this specific problem?
Putting an input in the header facet is not valid. If you want to use it as a filter or something, put it in a f:facet name="filter".
<p:dataTable id="myDataTable" var="row" ...>
<p:column filterBy="#{row.myCol1}" sortBy="#{row.myCol1}">
<f:facet name="header">
<div><h:outputText value="My Column 01" /></div>
</f:facet>
<f:facet name="filter">
<p:autoComplete ...>
<p:ajax event="itemSelect" update="myDataTable" />
</p:autoComplete>
</f:facet>
<h:outputText value="#{row.myCol1}" />
</p:column>
But you might need to improve on the way the filter is used by not using the p:ajax but use an onchange=PF('dataTableWidget').filter(), adding a widgetVar attribute and adding filter attributes
See also
PrimeFaces showcase dataTable filter
Basically, I have 2 collections of objects: List and List. Each person has a value in each criteria, which builds the matrix to be displayed:
criteria1 criteria2 criteria3 ...
person1 2 5 8
person2 4 3 1
person3 6 9 0
...
The number of elements in each collection is unknown since they are coming from query results. My model has 3 tables: criteria, person and criteria_person (which has the personId, criteriaId and qualification).
I have been able to display the datatable with these collections but I have no clue about how to relate them to the qualification associated to them, and then make them persist. So, any guidance would be much appreciated.
You just asked such a wide question. For this you can use row expansion see more
You can simple add a table with person name and criteria would be it's inner table like in the example on the showcase.
here is sample example:
<p:dataTable var="person" value="#{dtBasicView.peronsViewList}">
<f:facet name="header">
Person with criteria
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Person Name">
<h:outputText value="#{person.personName}" />
</p:column>
<p:column headerText="Reg. Date">
<h:outputText value="#{person.regDate}" />
</p:column>
<p:rowExpansion>
<p:panelGrid columns="2" columnClasses="label,value" style="width:300px">
<p:dataTable var="cri" value="#{person.criteria}">
<p:column headerText="Id">
<h:outputText value="#{cri.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{cri.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{cri.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{cri.color}" />
</p:column>
</p:dataTable>
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
I am not sure if I understood the question 100%, but I solved something similar with p:columns and a backing bean method which resolves the value for the current cell:
<p:dataTable value="#{curSearch.getSearchResults()}" var="curSearchResult">
<p:columns value="#{curSearch.determineItems()}" var="curSearchItem">
<f:facet name="header">
<h:outputText value="#{curSearchItem}" />
</f:facet>
<h:outputText value="#{someUiBusinessLogicBean.generatePropertyValue(curSearchResult, curSearchItem)}" />
</p:columns>
</p:dataTable>
Hope this shows the idea. But I would recommend to build a handy UI model.
I'm using a datatable with filtering. This is the table declaration:
<p:dataTable id="#{tblId}" var="p" editable="true" editMode="cell"
resizableColumns="true" rowIndexVar="rowIndex" selectionMode="multiple"
rowKey="#{p.id}" selection="#{ppselection}"
emptyMessage="No Params in table" value="#{tblValue}" scrollable="true"
style="height:100%" sortMode="multiple" styleClass="#{styleClass}"
filteredValue="#{filteredParams}">
When adding a new row to the table, I want it to already be displayed according to the current filter. i.e. if the filter is "aa" and the row name is "aabbcc" then I want it displayed, but if the row name is "bbcc" then I don't want it displayed. Right now, all I came up with is decidng whether I want to manually add it to the filteredParams list or not.
This is an example of one of the columns in the table, although all the coulmns are filterable:
<p:column width="15%" id="ParameterColumn" headerText="Parameter" sortBy="#{p.name}"
filterBy="#{p.name}" filterMatchMode="contains">
<p:cellEditor id="Parameter">
<f:facet name="output">
<h:outputText id="param_name" value="#{p.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="nameInput" value="#{p.name}" style="width:99%"
validator="#{p.validateParamName}">
<p:ajax event="change"
update=":main_tabs:paramForm:ParamTbl, :main_tabs:paramForm:SplitedParamTbl" />
</p:inputText>
<p:messages for="nameInput" display="tooltip" />
</f:facet>
</p:cellEditor>
</p:column>
Thanks!!
You can trigger filtering in oncomplete method of ajax/button that adds new row:
oncomplete='tableWidgetVar.filter();'
The datatable show this column (and others):
<p:column id="columnId" headerText="#{bundle.headerColumn}"
rendered="#{item.condition()}" >
<p:cellEditor id="cellEditId">
<f:facet name="output" >
...
</f:facet>
<f:facet name="input">
...
</f:facet>
</p:cellEditor>
</p:column>
ajax update the data table:
<p:ajax event="cellEdit" listener="#{controller.onCellEdit}"
update="dataTableId" />
but the column header of this column is not showed after ajax updates.
The column rows and footer are showed ok and the headers of columns at right are shifted one column to left.
Before ajax, the html rendered is:
<span><span>Header Text</span></span></th>
But the code after ajax update is:
<span>Header Text</span></th>
Other columns are ok but they don't have rendered attribute.
Put this in your datatable:
<p:columnGroup type="header">
<p:row>
<p:column headerText="Select" />
<p:column headerText="Name activity" />
<p:column headerText="View activity" />
<p:column headerText="Consistency and completeness" />
</p:row>
</p:columnGroup>
This is a header's of your table...after put your columns.
Here there a example: http://www.primefaces.org/showcase/ui/datatableGrouping.jsf
By.