Difference between revisions of "Documentation/DevGuide/Forms/Filtering and Sorting"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m
Line 7: Line 7:
 
}}
 
}}
 
{{DISPLAYTITLE:Filtering and Sorting}}
 
{{DISPLAYTITLE:Filtering and Sorting}}
Forms support quick and easy filtering and sorting like the underlying row sets. For this, the properties [http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/RowSet.html#Filter com.sun.star.sdb.RowSet:Filter], [http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/RowSet.html#ApplyFilter com.sun.star.sdb.RowSet:ApplyFilter] and [http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/RowSet.html#Order com.sun.star.sdb.RowSet:Order] area used.  
+
Forms support quick and easy filtering and sorting like the underlying row sets. For this, the properties <idlml>com.sun.star.sdb.RowSet:Filter</idlml>, <idlml>com.sun.star.sdb.RowSet:ApplyFilter</idlml> and <idlml>com.sun.star.sdb.RowSet:Order</idlml> area used.  
 
<!--[SOURCE:Forms/SalesFilter.java]-->
 
<!--[SOURCE:Forms/SalesFilter.java]-->
 
  <source lang="java">
 
  <source lang="java">
Line 25: Line 25:
 
In this fragment, a filter string is built first. The "<code>SALEDATE >= {D '2002-12-02'}</code>" is an example for a filter string. In general, everything that appears after the WHERE clause of an SQL statement is set as a <code>Filter</code> property value. The same holds true for the <code>Order</code> property value and an <code>ORDER BY</code> clause.
 
In this fragment, a filter string is built first. The "<code>SALEDATE >= {D '2002-12-02'}</code>" is an example for a filter string. In general, everything that appears after the WHERE clause of an SQL statement is set as a <code>Filter</code> property value. The same holds true for the <code>Order</code> property value and an <code>ORDER BY</code> clause.
  
{{Documentation/Tip|The notation for the date in braces: This is the standard ODBC notation for date values, and it is the safest method to supply {{PRODUCTNAME}} 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 [http://api.openoffice.org/docs/common/ref/com/sun/star/sdbc/Statement.html#EscapeProcessing com.sun.star.sdbc.Statement:EscapeProcessing]. {{PRODUCTNAME}} 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.}}
+
{{Documentation/Tip|The notation for the date in braces: This is the standard ODBC notation for date values, and it is the safest method to supply {{PRODUCTNAME}} 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 <idlml>com.sun.star.sdbc.Statement:EscapeProcessing</idlml>. {{PRODUCTNAME}} 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 <code>ApplyFilter</code> property is set to <code>true</code>. 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 <code>ApplyFilter</code> property at least once. Afterwards, <code>reload()</code> is called.
 
Then the <code>ApplyFilter</code> property is set to <code>true</code>. 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 <code>ApplyFilter</code> property at least once. Afterwards, <code>reload()</code> is called.

Revision as of 20:23, 6 April 2008



Forms support quick and easy filtering and sorting like the underlying row sets. For this, the properties <idlml>com.sun.star.sdb.RowSet:Filter</idlml>, <idlml>com.sun.star.sdb.RowSet:ApplyFilter</idlml> and <idlml>com.sun.star.sdb.RowSet:Order</idlml> 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);
  xLoad.reload();

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.

Template:Documentation/Tip

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