title: Refresh selection model of p:datatable on row deselection
body: <p>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.</p>
  
  <p>The following gives the definition of the datatable (reduced to relevant tags) - the data model is of type org.primefaces.model.LazyDataModel:</p>
  
  <pre><code>&lt;p:dataTable id="cases" 
      widgetVar="cases"
      var="cases"
      value="#{casesController.dataModel}"
      selection="#{casesController.selectedCases}"
      selectionMode="multiple"
      /&gt;
  </code></pre>
  
  <p>There is a Javascript function used in that project which processes clicks on rows to select and deselect the rows. </p>
  
  <pre><code>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 &amp;&amp; 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() &amp;&amp; event
                              &amp;&amp; !metaKey &amp;&amp; !shiftKey &amp;&amp; this.cfg.rowSelectMode === 'new')) {
                  this.unselectAllRows();
              }
  
              // range selection with shift key
              if (this.isMultipleSelection() &amp;&amp; event &amp;&amp; event.shiftKey) {
                  this.selectRowsInRange(row);
              }
              // select current row
              else {
                  this.originRowIndex = row.index();
                  this.cursorIndex = null;
                  this.selectRow(row, silent);
              }
          }
          PrimeFaces.clearSelection();
      }
  }
  </code></pre>
  
  <p>Debugging this script shows that the branches are passed as expected. But it seems to me, that unSelectRow() is not the opposite of selectRow(). </p>
  
  <p>Adding a comment around the javascript function to use the original Primefaces function has no effect on my problem.</p>