This Question is Answered

1 "correct" answer available (4 pts)
5 Replies Last post: Jun 16, 2008 1:20 PM by Roman Schwienbacher  
Roman Schwienbacher   35 posts since
Jan 16, 2008
Currently Being Moderated

Jun 13, 2008 2:31 PM

Multiple q:dataTables in one page: filtering

 

Hello to everybody,

 

 

I have a page with two dataTables. They have the same structure but only the data source (value) is different.

 

 

My question: I would like to implement the possibility to filter both tables at the same time. F.ex.: I have the column 'name' in both tables, so when I do the filtering on the first dataTable it should filter the second one too.

 

 

Is there any way to realize that??

 

 

 

 

Thank you in advance

 

 

Roman

 

 

Dmitry Pikhulya TeamDev Ltd. 162 posts since
Jan 5, 2007
Currently Being Moderated
1. Jun 13, 2008 3:25 PM in response to: Roman Schwienbacher
Re: Multiple q:dataTables in one page: filtering

Hello Roman,

 

You can consider the following two approaches to implement simultaneous filtering of two tables.

 

The first approach can be used if the layout of your page allows the second table to be placed in the "below" (or "above") facet of the first table. In this case you can set up filtering for both tables and bind the filterValue attribute of analogous columns from two tables to the same shared values. As a result, filtering a column in the first table will make the appropriate filterValue to be used by both tables, and the second table will be reloaded by any filtering action because it is located in the first table's "below" facet. The only additional thing that you will need to do in this approach is hide the filtering row in the second table to avoid specifying conflicting filter values for the same column. Here's an example that briefly outlines this approach:


<q:dataTable id="firstTable" value="#{DataBean.firstDataSet}" var="row">
  <q:column filterKind="searchField" filterExpression="#{row.col1}" filterValue="#{DataBean.col1FilterValue}">...<q:column>
  <q:column filterKind="searchField" filterExpression="#{row.col2}" filterValue="#{DataBean.col2FilterValue}">...<q:column>
  ...
  <f:facet name="below">
    <q:dataTable id="secondTable" value="#{DataBean.secondDataSet}" var="row">
      <q:column filterKind="searchField" filterExpression="#{row.col1}" filterValue="#{DataBean.col1FilterValue}">...<q:column>
      <q:column filterKind="searchField" filterExpression="#{row.col2}" filterValue="#{DataBean.col2FilterValue}">...<q:column>
      ...
    </q:dataTable>
  </f:facet>
</q:dataTable>

 

The second approach is to use manual filtering and Ajax4jsf for reloading both tables at once. This approach can be used if it's not possible to place one table inside of the "below" or "above" facet of another one. In this case you will need to place the filtering parameter components outside of both tables, with the "search" button having to submit these parameters and reload the two tables according to these parameters. Note that you can still utilize the filtering capabilities of the tables by providing the filtering parameters throught the filterValue attributes and hiding the filtering rows to disable inplace filtering (similarly to the way it is done for the second table in the first approach).

 

Feel free to ask if you have any questions.

 

Regards,

Dmitry

Dmitry Pikhulya TeamDev Ltd. 162 posts since
Jan 5, 2007
Currently Being Moderated
3. Jun 14, 2008 2:57 PM in response to: Roman Schwienbacher
Re: Multiple q:dataTables in one page: filtering

Roman,

 

The set of actual classes whose instances are allowed in the filterValue attribute depends on the kind of filter that you use for the appropriate column -- see the Filtering section in DataTable documentation and the Tag Reference. Though it's always safe to declare the binding to have a common base class for all of them, that is the teamdev.jsf.component.datatable.ColumnFilterCriterion class.

 

Regards,

Dmitry

More Like This

  • Retrieving data ...