Refresh selection model of p:datatable on row deselection

1.5k views Asked by At

I have a problem with the selection model of a Primefaces 5.0 datatable. This selection model does not process deselection properly: Selection of rows adds these roles as expected to the list of selected rows. But a deselection has no influence on this list; deselected rows remains in it. Only deselecting all rows produces an empty list.

The following gives the definition of the datatable (reduced to relevant tags) - the data model is of type org.primefaces.model.LazyDataModel:

<p:dataTable id="cases" 
    widgetVar="cases"
    var="cases"
    value="#{casesController.dataModel}"
    selection="#{casesController.selectedCases}"
    selectionMode="multiple"
    />

There is a Javascript function used in that project which processes clicks on rows to select and deselect the rows.

onRowClick : function(event, rowElement, silent) {
    // Check if rowclick triggered this event not a clickable
    // element in row content
    if ($(event.target).is('td,span:not(.ui-c)')) {
        var row = $(rowElement),
            selected = row.hasClass('ui-state-highlight'),
            metaKey = event.metaKey || event.ctrlKey,
            shiftKey = event.shiftKey;
            mouseBtn = event.which;

        // unselect if already selected on leftClick/touch to enable
        // contextMenu to be shown on rightclick
        if (selected && mouseBtn == 1) {
            this.originRowIndex = row.index();
            this.cursorIndex = null;
            this.unselectRow(row, silent);
        } else {
            // unselect previous selection if this is single
            // selection or multiple one with no keys
            if (this.isSingleSelection()
                    || (this.isMultipleSelection() && event
                            && !metaKey && !shiftKey && this.cfg.rowSelectMode === 'new')) {
                this.unselectAllRows();
            }

            // range selection with shift key
            if (this.isMultipleSelection() && event && event.shiftKey) {
                this.selectRowsInRange(row);
            }
            // select current row
            else {
                this.originRowIndex = row.index();
                this.cursorIndex = null;
                this.selectRow(row, silent);
            }
        }
        PrimeFaces.clearSelection();
    }
}

Debugging this script shows that the branches are passed as expected. But it seems to me, that unSelectRow() is not the opposite of selectRow().

Adding a comment around the javascript function to use the original Primefaces function has no effect on my problem.

1

There are 1 answers

0
AnnetteC On BEST ANSWER

I finally found the solution. They had extended PrimeFaces implemenation and incompletely implemented some methods. The following thread helped me in solving the problem: p:dataTable selections are lost after paginating a LazyDataModel