Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Grid DW

Status
Not open for further replies.

ahmedhossni

Programmer
May 1, 2010
6
EG
Please I want to sort "Asending-Descending" the Grid Datawindow when the user click on the column header

ex:

Order Desc Quantity
10 VISA 100
20 MASTERCARD 400
30 PAYPAL 150


When user click quantity, the datawindow will sort it with highest quantity first and viceversa when he click it again it will sort it lowest quantity first...
can it be applied on all columns ??


Thank You Very Much

 
This is for simple, single column sorting.

Code:
//Clicked event of datawindow
// You need an instance variable (string is_sort_column)
// This script first checks to see if we've clicked in the header area or
// the detail area.  If we've clicked in the header area, it tries to sort
// the datawindow on the column header we've clicked on.  

Integer ll_tab_pos
String ls_object_at_pointer
String ls_object_type
String ls_sort_format, ls_sort_data,ls_sort_fld_type
String ls_editstyle
String ls_band_at_pointer

IF row > 0 THEN
  // do something else
ELSE
  // If we've clicked in the header band, get the name of the object we've
  // clicked on and sort on its related column.  This functionality is
  // dependent on the text object name (column label) having the same name as the column
  // name with an additional "_t" to indicate it's a text object.  For
  // example, the label for the "empid" column would be "empid_t".

  ls_band_at_pointer = This.GetBandAtPointer()
  ll_tab_pos = Pos(ls_band_at_pointer, "	", 1)

  ls_band_at_pointer = Trim(Left(ls_band_at_pointer,   ll_tab_pos - 1))
  IF ls_band_at_pointer = "header" THEN
	ls_object_at_pointer = This.GetObjectAtPointer()
	IF ls_object_at_pointer <> "" THEN
		ll_tab_pos = Pos(ls_object_at_pointer, "	", 1)
		ls_object_at_pointer = Trim(Left(ls_object_at_pointer, ll_tab_pos - 1))
		ls_object_type = This.Describe(ls_object_at_pointer + ".Type")
		IF ls_object_type = "text" THEN
			// if second time to click this column, sort descending
			IF is_sort_column = ls_object_at_pointer THEN
				is_sort_column = ""
				ls_sort_data = Left(ls_object_at_pointer, Len(ls_object_at_pointer) - 2)
				ls_sort_fld_type = This.Describe(ls_sort_data+ ".Coltype")
				CHOOSE CASE lower(ls_sort_fld_type)
					CASE 'date','datetime'
						ls_sort_format =  ls_sort_data + " D"
						
					case else
						ls_editstyle = this.Describe(ls_sort_data + ".Edit.Style")
						CHOOSE CASE lower(ls_editstyle)
							CASE 'edit', '!', 'editmask', 'checkbox'
								ls_sort_format = ls_sort_data + " D"
							CASE ELSE
								ls_sort_format = "LookUpDisplay(" + ls_sort_data + ")" + " D"
						END CHOOSE
				end choose
			
			ELSE
				is_sort_column = ls_object_at_pointer
				ls_sort_data = Left(ls_object_at_pointer, Len(ls_object_at_pointer) - 2)
				ls_sort_fld_type = This.Describe(ls_sort_data+ ".Coltype")
				CHOOSE CASE lower(ls_sort_fld_type)
					CASE 'date','datetime'
						ls_sort_format =  ls_sort_data + " A"
					case else
						ls_editstyle = this.Describe(ls_sort_data + ".Edit.Style")
						CHOOSE CASE lower(ls_editstyle)
							CASE 'edit', '!', 'editmask', 'checkbox'
								ls_sort_format = ls_sort_data + " A"
							CASE ELSE
								ls_sort_format = "LookUpDisplay(" + ls_sort_data + ")" + " A"
							END CHOOSE
				END CHOOSE
			END IF
			IF This.SetSort(ls_sort_format) = 1 THEN
				SetPointer(HourGlass!)
				This.Sort()
				This.SetRedraw(True)
			END IF
		END IF
	END IF // IF ls_object_at_pointer <> "" THEN
  END IF // IF ls_band_at_pointer = "header" THEN
END IF

Matt

"Nature forges everything on the anvil of time"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top