How to make Selection Disable/Enable dynamically in DataTable - jsf

How can I make the Primefaces p:dataTable selection Enable or Disable or Multiple or Single dynamically based on some condition.

There is disabledSelection attribute of p:dataTable in PrimeFaces 5+. Using this attribute with proper data table update, enable/disable row selection can be reached.

Related

Editable TreeTable in PrimeFaces

I have a project where I use the PrimeFaces Framework. Now I need an tree-organized table, where the cells are editable. I've found an example with OpenFaces, that is exactly what I need:
http://openfaces.org/demo/treetable/TreeTable_selectionAndKeyboard.jsf
is it possible to make that in PrimeFaces?

select All/deselect all checkbox in Datatable JSF without using Javascript

I am making datatable in JSF using (dataTable tag).
I am having several rows in that with check box( selectBooleanCheckbox ) in front of every record.
I have commandLink button for selecting all check box and deselected all check box..
i am trying to select/unselect all checkboxes in the datatable using a single commandLink. As I am trying to set it on the server, I am unable to do so. I have looked around for solutions but could not get how to accomplish on the server side.
thnks

p:ajax event for pagination of lazy p:dataTable

I'm having trouble finding an ajax event that will execute my javascript when my list is updated during lazy loading of my datatable. This javascript is responsible for updating an image coverflow based upon my list that gets repopulated during initial datatable loading, when doing pagination, and changing the number of records on a page. Any help with finding a way to make an event execute my javascript during these situations is greatly appreciated! Thanks in advance!
Primefaces 3.3.1
Mojarra 2.1.5
JBoss AS 7.1.0.Final
Its not specific for Lazy Loading :
In order to run a js function upon pagination complete use the p:ajax event="page" (It might also work for changing the number of records on a page)
Like this
<p:ajax event="page" oncomplete="myJsFunction();"></p:ajax>
Additional event types are
page - On pagination.
sort - When a column is sorted.
filter - On filtering.
rowSelect - When a row is being selected.
rowUnselect - When a row is being unselected.
rowEdit - When a row is edited.
rowEditCancel - When row edit is cancelled.
colResize - When a column is being selected.
toggleSelect - When header checkbox is toggled.
colReorder - When columns are reordered.
rowSelectRadio - Row selection with radio.
rowSelectCheckbox - Row selection with checkbox.
rowUnselectCheckbox - Row unselection with checkbox.
rowDblselect - Row selection with double click.
rowToggle - Row expand or collapse.
contextMenu - ContextMenu display.
(Taken from primefaces user guide)
In primefaces 6.2, here is the full list of dataTable events.
page
sort
filter
rowSelect
rowUnselect
rowEdit
rowEditInit
rowEditCancel
colResize
toggleSelect
colReorder
contextMenu
rowSelectRadio
rowSelectCheckbox
rowUnselectCheckbox
rowDblselect
rowToggle
cellEditInit
cellEdit
rowReorder
swipeleft
swiperight
tap
taphold
cellEditCancel
from the docs: javax.faces.component.behavior.ClientBehaviorHolder.getEventNames()

Primefaces: selectionMode multiple/ set Value of Checkbox

I´ve implemented a datatable in JSF with a column with a attribute selectionMode="multiple".
Everything is working so far.
Is there a way to manipulate the value of the checkbox? I want to set the checkbox on the first load to checked or to unchecked, depending on a specific value.
The function i have implemented (in java) returns already true or false, but i need to set the checkboxValue to that value. What do i have to do to ?
You can manipulate the checkbox value through the value attribute like for any other component. See the DataTable demo with multiple selection:
DataTable - RadioCheckbox

call a custom listener for cancel in p:rowEditor

I have been trying to call a custom listener when the cancel button is clicked in the primefaces rowEditor component. But I am not able to find the correct attribute to do this.
The problem with the cancel button is that it works fine when the row is already present in the dataTable, if I try to add a new row dynamically to the dataTable and click on the cancel button [ if I think that it is not required ], the empty row is shown in the dataTable, when the empty row should be deleted.
Would you please help me out ?
Try like (JSF2 + Primefaces 2.2.1) ...
<p:column headerText="Test">
<p:rowEditor>
<p:ajaxStatus oncomplete="#{yourBean.yourHandleMethod()}"></p:ajaxStatus>
</p:rowEditor>
</p:column>
I am afraid this functionality isn't available out of box. The rowEditor component has built in integration to a dataTable and its own events and listeners for editing a single existing row. The cancel button of the rowEditor component has the sole functionality of toggling the output and input facets of the Primefaces column components.
If you are good at jQuery you may be able to hack the functionality in by finding the DOM element by the cancel button class, jQuery('.ui-icon-close') and assigning a custom javascript event listener but this could be problematic in a dataTable where there are multiple rows and it sounds as if you would like to delete a blank row if Cancel is selected.
A better approach is create an Add New button that displays a dialog with a form. Submitting through the form in the dialog can add the necessary row to your dataTable.

Resources