I have a editable primefaces datatable with checkboxes as one of the column.Is there any way to uncheck all checked checkboxes on click of the command button.
My JSF page code snippet.
<h:form id="form">
<h:selectOneMenu id="workspaceOptions"
value="#{tableBean.selectedItem}" class="selectMenu">
<f:selectItem id="item1" itemLabel="Select" itemValue="#{null}" />
<f:selectItem id="item2" itemLabel="Assignments"
itemValue="assignment" />
<f:selectItem id="item3" itemLabel="Preview" itemValue="2" />
<f:selectItem id="item4" itemLabel="Print" itemValue="3" />
<f:selectItem id="item5" itemLabel="Refresh" itemValue="4" />
<f:selectItem id="item6" itemLabel="Clear checkmarks" itemValue="5" />
</h:selectOneMenu>
<h:commandButton value="GO" class="commandButton"
action="#{tableBean.submit}" />
<br />
<br />
<br />
<p:dataTable id="multiCars" var="car"
value="#{tableBean.mediumCarsModel}"
selection="#{tableBean.selectedCars}" editable="true" editMode="cell">
<f:facet name="header">
Checkbox Based Selection
</f:facet>
<p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}"
update=":form:messages" />
<p:column headerText="Model" style="width:25%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.model}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{car.model}"
style="width:96%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Year" style="width:25%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.year}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.year}" style="width:96%" label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column selectionMode="multiple" style="width:2%;align:middle">
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
</p:column>
<p:column headerText="Manufacturer" style="width:25%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.manufacturer}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.manufacturer}" style="width:96%"
label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Color" style="width:25%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.color}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.color}" style="width:96%" label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<f:facet name="footer">
<p:commandButton id="multiViewButton" value="View"
icon="ui-icon-search" action="#{tableBean.getSelection}" />
</f:facet>
</p:dataTable>
</h:form>
I am ok with handling of this functionality at either client side or server side.
If you want to use a separate button, then you can call the Javascript method provided in the PrimeFaces documentation.
unselectAllRows() - Unselects all rows.
You would do this by providing your DataTable a widgetVar:
<p:dataTable id="multiCars" widgetVar="multiCars" ... >
then calling it from a commandButton of type "button" (for client-side processing):
<p:commandButton type="button" value="Deselect All"
onclick="multiCars.unselectAllRows();" />
That said, why don't you just use a select all/deselect all option provided by the framework? If you remove the header facet of your selectionmode="multiple" column, then it will display a checkbox allowing you to select or deselect all.
So instead of
<p:column selectionMode="multiple" style="width:2%;align:middle">
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
</p:column>
Use this (I removed the align:middle CSS attribute because it doesn't do anything):
<p:column selectionMode="multiple" style="width:2%" />
Related
I would like to render p:selectOneMenu inside p:dataTable upon rowEditInit event. I tried update="degreeType", update=formid:editTable:degreeType but it didn't work. update="#this is not a option as it refreshes whole table and clears the edit selection. As it is a dataTable, the exact id for the element is formid:editTable:0:degreeType, 0 being row number. How should I get the current row id number and put in update field?
<p:dataTable id="editTable" value="#{bean.emp}" var="stud" disabledSelection="true" editable="true" >
<p:ajax event="rowEditInit" listener="#{bean.onRowInit}" update="degreeType"/>
<p:ajax event="rowEdit" listener="#{bean.onRowEdit}" />
<p:ajax event="rowEditCancel" listener="#{bean.onRowCancel}" />
<!-- a bunch of p:column tags -->
<p:column headerText="Degree">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{stud.degree}" /></f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{stud.degree}" style="width: 100%" >
<f:ajax event="change" listener="#{bean.degreeListener}" render="degreeType" />
<f:selectItem itemLabel="Select One" itemValue=""/>
<f:selectItem itemLabel="MS" itemValue="MS"/>
<f:selectItem itemLabel="BS" itemValue="BS"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="DegreeType">
<p:cellEditor id="test">
<f:facet name="output"><h:outputText value="#{stud.degreeType}" /></f:facet>
<f:facet name="input">
<p:selectOneMenu id="degreeType" value="#{stud.degreeType}" rendered="true">
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{stud.degreeTypes}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width: 30px">
<p:rowEditor />
</p:column>
</p:dataTable>
I'm using <p:rowEditor> as follows:
<p:column headerText="Libellé">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lot.libelle}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lot.libelle}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:rowEditor />
</p:column>
I would like to show a confirm message before the <p:rowEditor> updates the model on click of the "OK" button. How can I achieve this?
You can use onstart attribute of <p:ajax event="rowEdit"> for this.
<p:dataTable ...>
<p:ajax event="rowEdit" onstart="return confirm('Are you sure?')" />
...
</p:dataTable>
I have this autocomplete component below that works outside the datatable but it doesn't work inside it
I don't see the cause :
<p:dataTable id="table" var="car" editable="true" editMode="cell"
widgetVar="carsTable" rowKey="#{car.idarticleFourniseur}"
value="#{articlesMB.listarticlefournisseurs}" rows="3">
<p:ajax event="cellEdit" listener="#{articlesMB.onCellEdit}"
update=":messages" />
<p:column headerText="Id">
<h:outputText value="#{car.idarticleFourniseur}" />
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{car.libelle}" />
</p:column>
<p:column headerText="Fournisseur">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.fournisseur.personne.nom}" />
</f:facet>
<f:facet name="input">
<p:autoComplete id="dfdd" var="p" itemLabel="#{p.personne.nom}"
itemValue="#{p}" dropdown="true" process="#this"
value="#{articlesMB.selectedFournisseur}"
forceSelection="true" converter="#{fournisseursConverter}"
completeMethod="#{articlesMB.complete}">
<p:column>
#{p.personne.nom} - #{p.personne.prenom}
</p:column>
</p:autoComplete>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<p:autoComplete id="dfd" var="p" itemLabel="#{p.personne.nom}"
itemValue="#{p}" dropdown="true" process="#this"
value="#{articlesMB.selectedFournisseur}" forceSelection="true"
converter="#{fournisseursConverter}"
completeMethod="#{articlesMB.complete}">
<p:column>
#{p.personne.nom} - #{p.personne.prenom}
</p:column>
</p:autoComplete>
the second autocomplete works fine, but the first (in datatable) doesn't work (the completion does not appear)
do you have any idea
thank you in advance
Instead of celleditor you can use inplace
<p:inplace editor="true" label="#{contactRole.userDto.fullContactData}" emptyLabel="#{msgs['constructionSite.text.contact']}">
<p:autoComplete value="#{contactRole.userDto}"
id="contact1" completeMethod="#{assignContactBean.completeContacts}"
var="c" itemLabel="#{c.fullContactData}" itemValue="#{c}"
converter="#{assignContactBean}" forceSelection="true" scrollHeight="200"/>
</p:inplace>
I'm using a p:dataTable to display a list of objects and I would like to order them by their Date property in a descending manner here is the code:
<h:form id="receivablesForm">
<p:dataTable id="receivablesTable" value="#{receivableManager.overdueReceivables}" var="receivable" rows="18" emptyMessage="#{msg['warning.noData']}" style="width: 585px;" sortBy="#{receivable.dueDate}" sortOrder="descending">
<p:column sortBy="#{receivable.invoice.number}" styleClass="fixedSizeColumnSmall">
<f:facet name="header">
<h:outputText value="#{msg['label.number']}" />
</f:facet>
<h:outputText value="#{receivable.invoice.number}-#{receivable.number}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg['label.clientName']}" />
</f:facet>
<h:outputText value="#{receivable.invoice.client.person.name}" />
</p:column>
<p:column styleClass="fixedSizeColumn">
<f:facet name="header">
<h:outputText value="#{msg['label.dueDate']}" />
</f:facet>
<h:outputText value="#{receivable.dueDate}" style="#{receivableManager.isOverdue(receivable) ? 'color: red' : ''}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{msg['label.amount']}" />
</f:facet>
<h:outputText value="#{receivable.amount}">
<f:convertNumber type="currency" locale="pt_br" />
</h:outputText>
</p:column>
</p:dataTable>
</h:form>
However the objects are not being ordered at all. Is it possible to order by a Date property in a descending manner using the sortBy and sortOrder properties?
Call a method of backingbean when finished filtering the table ends. Using Primefaces, datatable look like this:
<p:dataTable id="tabla_gral" rendered="#{consumoMaterial.verTabla}" var="item" paginator="true" rows="15" rowKey="#{item.no}" value="#{consumoMaterial.listadoConsumo}" filteredValue="#{consumoMaterial.listadoConsumoFiltered}">
<p:ajax event="filter" listener="#{consumoMaterial.actualizarSaldos}" update=":form2:tabla_gral" />
<f:facet name="header">
<h:outputText value="Búsqueda de Consumo por: #{consumoMaterial.tipoBuscar}: '#{consumoMaterial.codigo}'" />
</f:facet>
<p:column exportable="#{consumoMaterial.no}" rendered="#{consumoMaterial.no}" id="cclave" sortBy="#{item.no}" filterBy="#{item.no}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nro" />
</f:facet>
<h:outputText value="#{item.no}" />
</p:column>
<p:column exportable="#{consumoMaterial.centroCosto}" rendered="#{consumoMaterial.centroCosto}" id="cconcepto" sortBy="#{item.centroCosto}" filterBy="#{item.centroCosto}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Centro de Costo" />
</f:facet>
<h:outputText value="#{item.centroCosto}" />
</p:column>
<p:column exportable="#{consumoMaterial.codigoAlmacen}" rendered="#{consumoMaterial.codigoAlmacen}" id="ctipo" sortBy="#{item.codigoAlmacen}" filterBy="#{item.codigoAlmacen}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Almacén" />
</f:facet>
<h:outputText value="#{item.codigoAlmacen}" />
</p:column>
</p:dataTable>
ajax event="filter" does not work because is while filtering not when it finish.
You can: in filter event, you call JavaScript function in oncomplete or onsuccess(it depend on your target), the JavaScript function will fire click event to commandbutton, and you put action code you want to that commandbutton:
<h:form id="form">
<script type="text/javascript">
function test(){
$(PrimeFaces.escapeClientId('form:btn')).click();
}
</script>
<p:commandButton style="display:none !important" id="btn" oncomplete="alert('ab');" value="SB"/>
<p:dataTable var="carr" value="#{tabview.l1}" id="carList" >
<p:ajax event="filter" oncomplete="test();"/>
<p:column filterMatchMode="contains" filterBy="#{carr.model}" headerText="Model" style="width:30%">
<h:outputText value="#{carr.model}" />
</p:column>
<p:column headerText="MANUFAC" style="width:20%">
<h:outputText value="#{carr.manufacturer}" />
</p:column>
</p:dataTable>
</h:form>