Filtering and Sorting

From Apache OpenOffice Wiki
Jump to: navigation, search

Forms support quick and easy filtering and sorting like the underlying row sets. For this, the properties Filter, ApplyFilter and Order area used.

  // set this as filter on the form
  String sCompleteFilter = "";
  if ((null != sOdbcDate) && (0 != sOdbcDate.length())) {
      sCompleteFilter = "SALEDATE >= ";
      sCompleteFilter += sOdbcDate;
  m_xSalesForm.setPropertyValue("Filter", sCompleteFilter);
  m_xSalesForm.setPropertyValue("ApplyFilter", new Boolean(true));
  // and reload the form
  XLoadable xLoad = (XLoadable)UnoRuntime.queryInterface(XLoadable.class, m_xSalesForm);

In this fragment, a filter string is built first. The "SALEDATE >= {D '2002-12-02'}" is an example for a filter string. In general, everything that appears after the WHERE clause of an SQL statement is set as a Filter property value. The same holds true for the Order property value and an ORDER BY clause.

Tip.png The notation for the date in braces: This is the standard ODBC notation for date values, and it is the safest method to supply Apache OpenOffice with date values. It also works if you are using non-ODBC data sources, as long as you do not switch on the Native SQL option. Refer to EscapeProcessing. Apache OpenOffice understands and sometimes returns other notations, for instance, in the user interface where that makes sense, but these are locale-dependent, which means you have to know the current locale if you use them.

Then the ApplyFilter property is set to true. This is for safety, because the value of this property is unknown when creating a new form. Every time you have a form or row set, and you want to change the filter, remember to set the ApplyFilter property at least once. Afterwards, reload() is called.

In general, ApplyFilter allows the user of a row set to enable or disable the current filter quickly without remembering it. To see what the effects of the current filter are, set ApplyFilter to false and reload the form.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages