3 Replies Latest reply on Nov 22, 2011 9:09 AM by Rubén Darío López Rojas

    How to get the rendered rows of a dataTable?

    Rubén Darío López Rojas Newbie

      Hi.

       

      I have a table (ExtendedDataTable with ExtendedTableDataModel as dataModel) in wich the user can sort columns and filter the rows, the table is also paginated (DataScroller). For example:

       

      {code}

      <rich:extendedDataTable

        value="#{dataModel}"

        var="_entity"

        rows="50" ... >

       

        <rich:column

          sortable="true"

          sortBy="#{_entity.code}"

          filterBy="#{_entity.code}"

          filterEvent="onkeyup">

       

          <h:outputText value="#{_entity.code}" />

                          </rich:column>

        ...

       

        <f:facet name="footer">

          <rich:datascroller id="ds" />

        </f:facet>

      </rich:extendedDataTable>

      {code}

       

      My question is, How can I get the rendered data after filtering and sorting?

       

      I'm using RichFaces 3.3. Thanks in advance.

        • 1. Re: How to get the rendered rows of a dataTable?
          Christian Peter Expert

          instead of value="#{datamodel}" being somekind of List<?>, you have to use an ExtendedTableDataModel (I'm not quite sure what the correct name was) or a ModifyableDataModel. After clientside filtering you can retrieve the actual visible rows (including pagination).

           

          from: http://community.jboss.org/wiki/HowToGetFilteredDataFromTableToList :

           

          public ModifiableModel getDataModel() {
               if (this.DataModel == null) {
                    ExtendedTableDataModel<MyDataObj> model = new ExtendedTableDataModel<MyDataObj>(new DataProvider<MyDataObj>() {
                         private static final long serialVersionUID = 5054087821033164847L;

                         public MyDataObj getItemByKey(Object key) {
                              for (MyDataObj c : MyManagedBean.this.data) {
                                   if (key.equals(getKey(c))) {
                                        return c;
                                   }
                              }
                              return null;
                         }

                         public List<MyDataObj> getItemsByRange(int firstRow, int endRow) {
                              return MyManagedBean.this.data.subList(firstRow, endRow);
                         }

                         public Object getKey(MyDataObj item) {
                              return item.getId();
                         }

                         public int getRowCount() {
                              return MyManagedBean.this.data.size();
                         }
                    });

                    this.dataModel = new ModifiableModel(model, "row");
               }

               return this.dataModel;
          }

           

           

          public List<MyDataObj> getFilteredData() throws IOException {
                    final List<MyDataObj> filteredData = new ArrayList<MyDataObj>();
                    final ModifiableModel model = getDataModel();

                    getDataModel().walk(FacesContext.getCurrentInstance(), new DataVisitor() {
                              public void process(FacesContext context, Object rowKey, Object argument) {
                                        model.setRowIndex((Integer)rowKey);
                                        filteredData.add((MyDataObj) model.getRowData());
                              }
                    }, new SequenceRange(0, -1), null);

                    return filteredData;
          }


           

          http://opensourcejavaphp.net/java/jbossportletbridge/org/richfaces/demo/extendedDataTable/ExtendedTableBean.java.html

           

          http://docs.jboss.org/richfaces/3.3.X/3.3.2.GA/en/apidoc_impl/org/richfaces/model/ExtendedTableDataModel.html

          • 2. Re: How to get the rendered rows of a dataTable?
            Rubén Darío López Rojas Newbie

            Thanks!!

             

            That was waht I was looking for. Next time I will check out the knowledge base before asking

             

            Saludos.

            • 3. Re: How to get the rendered rows of a dataTable?
              Rubén Darío López Rojas Newbie

              Finally I used an ExtendedTableDataModifiableModel<T> instead of a ModifiableModel to make row selection work correctly on the ExtendedDataTable.

               

              Thanks again.