2 Replies Latest reply on Sep 23, 2015 9:50 AM by longyg Branched from an earlier discussion.

    how to select all current page items in rich:dataTable?

    longyg

      Hello, i have similar issue faced.

      I have a rich:dataTable, and sorting and filtering is implemented for each column, one of the column i have a checkbox which used to select all rows in current page.

      The problem is that when i checked the select all checkbox in page 1, all the rows are selected correctly, but then i switch to page 2, the select all checkbox is still checked, but basically it should be judged with whether all rows are selected in page 2, if not, the select all checkbox should not be checked.

      So i have to know all the objects of current page, but it's hard to get that if the table is sorted and filtered.

      Could anyone give me some suggestion how to solve it?

       

      <rich:dataTable id="table"
        value="#{model.displayedData}" var="data"
        rows="#{model.itemsPerPage}">
      
        <rich:column>
        <f:facet name="header">
        <h:panelGroup layout="block">
        <h:selectBooleanCheckbox id="HeaderCheckBox"
        disabled="#{model.selectAllDisabled}"
        value="#{model.selectAllChecked}" immediate="true">
        <a4j:support event="onclick" action="#{model.selectAll}" onclick="selectAll(this)" 
        reRender="table" status="commonstatus">
        <a4j:actionparam assignTo="#{model.allCurrentPageItems}" name="allItems" value="getAllCurrentPageIds()" noEscape="true"/>
        </a4j:support>
        </h:selectBooleanCheckbox>
        </h:panelGroup>
        </f:facet>
        <h:selectBooleanCheckbox
        value="#{data.selected}"
        disabled="#{data.disabled}" immediate="true">
        <a4j:support event="onclick" action="#{model.select}" onclick="clickcheckBoxhandling(this);" 
        reRender="table" status="commonstatus">
        <a4j:actionparam assignTo="#{model.seletedId}" name="seletedItem" value="#{data.id}" />
        <a4j:actionparam assignTo="#{model.selected}" name="itemSelection" value="this.checked" noEscape="true"/>
        </a4j:support>
        </h:selectBooleanCheckbox>
        </rich:column>
      

       

      The server side model bean is:

       

      private String seletedId;
      private boolean selected;
      private boolean selectAllDisabled;
      private boolean selectAllChecked;
      
      public List<DataModel> getDisplayedData() {
        if (filter.isFilterEmpty()) {
        displayedData = allData;
        } else {
        displayedData = filter.getFilteredData(allData);
        }
        return displayedData;
      }
      

       

      So i need to set the "selectAllChecked" property correctly when user switch to different page, sorting by each column and filter by each column. So i want to get the exact current pages data list even with sorted and filtered, so that i can judge whether all of the current pages data are selected or not to set the "selectAllChecked" property.

      So question is that, how could i get the current pages row objects? All is there any other way to implement my request above?