| Home | Previous Lesson: Saving Changes to the Database Next Lesson: Filtering the Data |
Calling Sort() function for the DataWindow, sorts the DataWindow on the specified criteria. However, Sort() itself takes no parameters. We need to set the sort criteria with another function namely SetSort(). For example, if you want to sort on product_no, you need to write the following code.
dw_product.SetSort( "product_no A")
To set the sort criteria on product_balance and product_no:
dw_product.SetSort( "product_balance A, product_no A")
We hard coded the sort criteria in the above statement. That's not practical. In real projects, we would like the user to sort data on the column(s) of his/her choice. This makes the application more interactive, dynamic and user-friendly.
What would happen if a null value is passed as an argument for SetSort(), and Sort() function is called ? As a result, sort criteria will not be available for PowerBuilder, so it will prompt for it.
A NULL value means unknown, or not defined. If a variable is set to a space, it has a value of " ". If you set it to a zero, it still has zero as its value. If you want to say you don't know the value, set the value to NULL. However, PowerBuilder doesn't support setting a variable value to NULL directly. You need to call SetNull() function for that.
// Object: cb_sort in w_product_master window.
// Event: Clicked
String Dummy
SetNull( Dummy)
dw_product.SetSort( Dummy)
dw_product.Sort()
| Home | Previous Lesson: Saving Changes to the Database Next Lesson: Filtering the Data |