{"id":132,"date":"2010-07-01T20:20:54","date_gmt":"2010-07-02T01:20:54","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=132"},"modified":"2021-03-08T19:55:57","modified_gmt":"2021-03-09T00:55:57","slug":"powerbuilder-simple-column-sort-by-click","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-simple-column-sort-by-click\/","title":{"rendered":"PowerBuilder &#8211; Simple datawindow column sort by click"},"content":{"rendered":"<p>This sample is for sorting the rows in a grid datawindow ascending or descending based on the user clicking the column header.  It only allows for a single column sort at a time.<\/p>\n<pre name=\"code\" class=\"VB\">\/\/Clicked event of datawindow\n\/\/ You need an instance variable (string is_sort_column)\n\/\/ This script first checks to see if we&#039;ve clicked in the header area or\n\/\/ the detail area.  If we&#039;ve clicked in the header area, it tries to sort\n\/\/ the datawindow on the column header we&#039;ve clicked on.  \n\nInteger ll_tab_pos\nString ls_object_at_pointer\nString ls_object_type\nString ls_sort_format, ls_sort_data,ls_sort_fld_type\nString ls_editstyle\nString ls_band_at_pointer\n\nIF row &gt; 0 THEN\n  \/\/ do something else\nELSE\n  \/\/ If we&#039;ve clicked in the header band, get the name of the object we&#039;ve\n  \/\/ clicked on and sort on its related column.  This functionality is\n  \/\/ dependent on the text object name (the column label) having the same \n  \/\/ name as the column name with an additional &quot;_t&quot;.  \n  \/\/ For example, the label for the &quot;empid&quot; column would be &quot;empid_t&quot;.\n\n  ls_band_at_pointer = This.GetBandAtPointer()\n  ll_tab_pos = Pos(ls_band_at_pointer, &quot;\t&quot;, 1)\n  ls_band_at_pointer = Trim(Left(ls_band_at_pointer, ll_tab_pos - 1))\n  IF ls_band_at_pointer = &quot;header&quot; THEN\n\tls_object_at_pointer = This.GetObjectAtPointer()\n\tIF ls_object_at_pointer &lt;&gt; &quot;&quot; THEN\n      ll_tab_pos = Pos(ls_object_at_pointer, &quot;\t&quot;, 1)\n      ls_object_at_pointer = Trim(Left(ls_object_at_pointer, ll_tab_pos - 1))\n      ls_object_type = This.Describe(ls_object_at_pointer + &quot;.Type&quot;)\n      IF ls_object_type = &quot;text&quot; THEN\n         \/\/ if second time to click this column, sort descending\n         IF is_sort_column = ls_object_at_pointer THEN\n           is_sort_column = &quot;&quot;\n           ls_sort_data = Left(ls_object_at_pointer, Len(ls_object_at_pointer) - 2)\n           ls_sort_fld_type = This.Describe(ls_sort_data+ &quot;.Coltype&quot;)\n           CHOOSE CASE lower(ls_sort_fld_type)\n             CASE &#039;date&#039;,&#039;datetime&#039;\n               ls_sort_format =  ls_sort_data + &quot; D&quot;\n             CASE ELSE\n               ls_editstyle = this.Describe(ls_sort_data + &quot;.Edit.Style&quot;)\n               CHOOSE CASE lower(ls_editstyle)\n                 CASE &#039;edit&#039;, &#039;!&#039;, &#039;editmask&#039;, &#039;checkbox&#039;\n                   ls_sort_format = ls_sort_data + &quot; D&quot;\n                 CASE ELSE\n                   ls_sort_format = &quot;LookUpDisplay(&quot; + ls_sort_data + &quot;)&quot; + &quot; D&quot;\n               END CHOOSE\n           END CHOOSE\n         ELSE\n           is_sort_column = ls_object_at_pointer\n           ls_sort_data = Left(ls_object_at_pointer, Len(ls_object_at_pointer) - 2)\n           ls_sort_fld_type = This.Describe(ls_sort_data+ &quot;.Coltype&quot;)\n           CHOOSE CASE lower(ls_sort_fld_type)\n             CASE &#039;date&#039;,&#039;datetime&#039;\n               ls_sort_format =  ls_sort_data + &quot; A&quot;\n             CASE ELSE\n               ls_editstyle = this.Describe(ls_sort_data + &quot;.Edit.Style&quot;)\n               CHOOSE CASE lower(ls_editstyle)\n                 CASE &#039;edit&#039;, &#039;!&#039;, &#039;editmask&#039;, &#039;checkbox&#039;\n                   ls_sort_format = ls_sort_data + &quot; A&quot;\n                 CASE ELSE\n                   ls_sort_format = &quot;LookUpDisplay(&quot; + ls_sort_data + &quot;)&quot; + &quot; A&quot;\n               END CHOOSE\n            END CHOOSE\n          END IF\n          IF This.SetSort(ls_sort_format) = 1 THEN\n             SetPointer(HourGlass!)\n             This.Sort()\n          END IF\n      END IF\n\tEND IF \/\/ IF ls_object_at_pointer &lt;&gt; &quot;&quot; THEN\n  END IF \/\/ IF ls_band_at_pointer = &quot;header&quot; THEN\nEND IF<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This sample is for sorting the rows in a grid datawindow ascending or descending based on the user clicking the column header. It only allows for a single column sort at a time. \/\/Clicked event of datawindow \/\/ You need an instance variable (string is_sort_column) \/\/ This script first checks to see if we&#039;ve clicked&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[21,12],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/132"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":14,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":1749,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/132\/revisions\/1749"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}