filter

Create DataWindow filter and activate the filter

Generate an error, if filter not correct.

Return always true.

 

A DataWindow object can have filter criteria specified as part of its definition. After data is retrieved, rows that do not meet the criteria are immediately transferred from the primary buffer to the filter buffer.

The Filter method replaces the existing filter criteria

The filter expression consists of columns, relational operators, and values against which column values are compared. Boolean expressions can be connected with logical operators AND and OR. You can also use NOT, the negation operator. Use parentheses to control the order of evaluation.

Sample expressions are:

 

dw_1.filter('item_id > 5 NOT item_id = 5 ');
dw_1.filter('(NOT item_id = 5) AND customer > "Mabson" ');
dw_1.filter('item_id > 5 AND customer = "Smith" ');
dw_1.filter('#1 > 5 AND #2 = "Smith"');

 

The filter expression is a string and does not contain variables. However, you can build the string in your script using the values of script variables. Within the filter string, string constants must be enclosed in quotation marks (see the examples).

more see datawindow expression

 

Dictionary or ASCII order

By default, PowerBuilder performs comparisons in dictionary order. For example, the following expression shows all the rows in which column 2 begins with A, a, B or b:

dw_1.setfilter("#2 >= 'a' and #2 < 'c'");

 

To perform comparisons in ASCII order, append \s to the format string. For example, the following expression shows only rows in which column 2 begins with a or b, because the ASCII values of uppercase letters are lower than the ASCII values of lowercase letters:

dw_1.setfilter("#2 >= 'a' and #2 < 'c' \s");

 

Number format

The formatting that you enter for numbers and currency in filter expressions display the same way in any country. Changing the regional settings of the operating system does not modify the formatting displayed for numbers and currency at runtime.

 

Escape keyword

If you need to use the % or _ characters as part of the string, you can use the escape keyword to indicate that the character is part of the string. For example, the _ character in the following filter string is part of the string to be searched for, but is treated as a wildcard:

comment LIKE "%o_a15progress%"

 

The escape keyword designates any character as an escape character (do not use a character that is part of the string you want to match). In the following example, the asterisk (*) character is inserted before the _ character and designated as an escape character, so that the _ character is treated as part of the string to be matched:

comment like "%o*_a15progress%" escape "*"

 

User-specified filters

To let users specify their own filter expression for a DataWindow control, you can pass a null string to the Filter method. Beas displays its Specify Filter dialog box with the filter expression blank. Then you can call Filter to apply the users filter expression to the DataWindow.

dw_1.filter();

dw_x_filter

 

Removing a filter

To remove a filter, call filter with the empty string ("") for format and then call Filter. The rows in the filter buffer will be restored to the primary buffer and positioned after the rows that already exist in the primary buffer.

dw_1.filter("");

 

Events

Follow events called (x=1-7):

dw_x_rowfocuschanged()

dw_x_filterchanged()

 

Example 1

This statement defines the filter expression for dw_1 as the value of format1:

dw_1.filter(format1);

 

Example 2

The following statements define a filter expression and set it as the filter for dw_1. With this filter, only those rows in which the cust_qty column exceeds 100 and the cust_code column exceeds 30 are displayed. The final statement calls Filter to apply the filter:

 

let DWfilter2 = "cust_qty > 100 and cust_code >30";
dw_1.SetFilter(DWfilter2)

 

Example 3

The following statements define a filter so that emp_state of dw_1 displays only if it is equal to the value of var1 (in this case ME for Maine). The filter expression passed to SetFilter is emp_state = ME:

 

let Var1 = "ME";
dw_1.filter("emp_state = '"+ var1 +" '");

 

Example 4

The following statements define a filter so that column 1 must equal the value in min_qty and column 2 must equal the value in max_qty to pass the filter. The resulting filter expression is:

#1=100 and #2=1000

 
The sample code is:

 

let min_qty = 100;
let max_qty = 1000;
dw_1.filter("#1="+ min_qty   + " and #2=" + max_qty);

 

Example 5

The following example sets the filter expression to null, which causes Beas to display the Specify Filter dialog box. Then it calls filter, which applies the filter expression the user specified:

dw_1.filter();