1 2 Previous Next 20 Replies Latest reply: Apr 8, 2009 9:43 AM by 388375 Go to original post RSS
      • 15. Re: Need to do column SORTING only when I click the column heading
        566555
        Denes - I love this solution and have used in an app I have in 3.1.1, but I have a current app in apex 2.0. Is there a way to accomplish this in 2.0 as well? I cannot get it to work since I cannot set the static region id in 2.0. How would I revise your solution to work in 2.0? Thanks!

        Mike
        • 16. Re: Need to do column SORTING only when I click the column heading
          Denes Kubicek
          Mike,

          Thanks. To be honest, I do not remember how to get the region_id in the version lower than
          2.2. Maybe someone else will know that.

          Denes Kubicek
          -------------------------------------------------------------------
          http://deneskubicek.blogspot.com/
          http://www.opal-consulting.de/training
          http://apex.oracle.com/pls/otn/f?p=31517:1
          -------------------------------------------------------------------
          • 17. Re: Need to do column SORTING only when I click the column heading
            566555
            Thanks Denes. I checked the app and the version is 2.1 (not that it matters much). I guess I just need to get that single app moved to 3.1.1, but I appreciate your input. Cheers.
            Mike
            • 18. Re: Need to do column SORTING only when I click the column heading
              531871
              Hi Denes - and Congratulations :-)

              I am new to Apex - and I also have this requerement.

              I have made the 2 fields (region_id and preference_removed) visible on the screen. Region_id is nicely printed with a long number - but when the process for making the preference_removed field runs, the region_id seems to be null ?? The preference_removed is filled out like this (FSP113_P8_R_SORT) and the region_id fiels is (4200408467350996)

              I have made the region_id a normal field with the sql in the source.

              The process is on page rendering - on load before header - I have tried it both with run once pr sesison and pr. page - same old same old ?

              Can you give a newbee a hint?

              best regards
              Mette
              • 19. Re: Need to do column SORTING only when I click the column heading
                Sumana
                Hi Mette,

                I guess the preference_removed process runs before your item region id is populated. Please check out the sequence of when your process gets executed. This can be easily checked by running your page in DEBUG mode.

                One idea is to have a computation before header to populate your region id. Then the process for preference_removed will run before header but after region id population (depending on the sequence no you give). Check this out if this has not yet been solved.

                Thanks,
                Sumana
                • 20. Re: Need to do column SORTING only when I click the column heading
                  388375
                  Hi Thread!

                  Andy (ATD) pointed me to this thread when I was looking to solve a templated report sorting problem.
                  See: Re: Sorting on columns with templated Report -- Named Column (row template)

                  I have a slightly different issue to solve than the original poster.
                  There's no requirement to change sorting persistence away from the APEX
                  way (persisting it per report and user).
                  Rather, I'm using a report with a column template, am therefore managing the
                  table headings myself and have to display the correct up/down arrow image
                  in the correct column to be in synch with the actual sort.

                  Reading through this thread I thought it should be possible to pick up the
                  user sort preference as described, and to use it to display the right .gif in the right column.

                  Everything works as expected, but the user preference that I read [Before Header]
                  appears to lag exactly one mouse click behind.

                  ** Picking up the pref [Before Header] and storing name/value in items so
                  Javascript code can access them:
                  declare
                    sort_pref VARCHAR2 (200) := null;
                  begin
                    select region_id
                    into :P401_REGION_ID
                    from apex_application_page_regions
                    where APPLICATION_ID = '124'
                      and page_id = '401'
                      and REGION_NAME = 'My Region';
                     sort_pref :=    'FSP'
                           || :app_id
                           || '_P'
                           || '401'
                           || '_R'
                           || :P401_REGION_ID
                           || '_SORT';
                    :P401_SORT_PREF_NAME := sort_pref;
                    :P401_SORT_PREF_VALUE := APEX_UTIL.GET_PREFERENCE ( sort_pref,:APP_USER);
                  end;
                  ** sample TH from Named Column Template (Before first and after last row text):
                  <th onClick="tt.sortByColumn('#REGION_ID#',4)">
                  <span style="cursor:pointer;text-decoration:underline" >MyColumn</span>
                  <img id="img_c4_up" height="12" width="13" alt="" src="/k/arrow_up_gray_dark.gif"/>
                  <img id="img_c4_down" height="12" width="13" alt="" src="/k/arrow_down_gray_dark.gif"/>
                  </th>
                  ** Javascript init code onLoad to show the right arrows:
                  this.sortPrefName = document.getElementById(sortPrefNameItem).value;
                  var sortStr = document.getElementById(sortPrefValueItem).value;
                  this.sortColumn = sortStr.substring(9,10);
                  this.sortOrder = sortStr.substring(11);     // if there's no '_desc', this will yield ''
                  for(var i in sortColumns){
                       document.getElementById("img_c"+sortColumns[i]+"_up").style.visibility = "hidden";
                       document.getElementById("img_c"+sortColumns[i]+"_down").style.visibility = "hidden";
                  }
                  
                  if(this.sortOrder == ''){
                       document.getElementById("img_c"+this.sortColumn+"_up").style.visibility = "visible";
                  }else{     // '_desc'
                       document.getElementById("img_c"+this.sortColumn+"_down").style.visibility = "visible";
                  }
                  ** Javascript click handler code to sort after mouse click on a column header:
                  this.sortByColumn = function (regionId,colNo){
                       if(colNo == this.sortColumn){
                            // user clicks the sorted columnheading again -> have to inverse the sort
                            if(this.sortOrder == ''){     // ASC
                                 this.sortOrder = '_desc';
                            }else{
                                 this.sortOrder = '';     // ASC
                            }
                       }else{
                            this.sortColumn = colNo;
                            this.sortOrder = '';     // ASC
                       }
                  
                       var u = "f?p=124:401:&SESSION.:fsp_sort_"+colNo+this.sortOrder+"::RP&fsp_region_id="
                       +regionId.substring(1);
                         document.location.href=u;
                  }
                  If sorting was on column 6 desc, say, and the user clicked on column 4 to
                  initially sort it ASC, and the actual sort that happens does exactly that,
                  the user preference will still report the sort state just before, column 6 desc.

                  If the user then clicks column 3, the preference will report the last column,
                  4, but surprisingly DESC instead of ASC.

                  I've tried to force update the pref using AJAX:
                  this.sortByColumn = function (regionId,colNo){
                       if(colNo == this.sortColumn){
                            // user clicks the sorted columnheading again -> have to inverse the sort
                            if(this.sortOrder == ''){     // ASC
                                 this.sortOrder = '_desc';
                            }else{
                                 this.sortOrder = '';     // ASC
                            }
                       }else{
                            this.sortColumn = colNo;
                            this.sortOrder = '';     // ASC
                       }
                  
                       var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=SET_PREFERENCE',0);
                       get.add( prefNameAppItem, this.sortPrefName );
                       get.add( prefValueAppItem, "fsp_sort_"+colNo+this.sortOrder );
                       gReturn = get.get();
                       get = null;
                  
                       var u = "f?p=124:401:&SESSION.:fsp_sort_"+colNo+this.sortOrder+"::RP&fsp_region_id="
                       +regionId.substring(1);
                         document.location.href=u;
                  }
                  ...But that just seems to confuse the pref in a different way, this way it
                  picks up the up-to-date column but still remembers the sort inversed.
                  So, when the user clicks on a new sort column, the pref picks that up but
                  will state the initial sort as DESC.

                  I wonder if these synch problems arise because I'm not submitting the page
                  and just setting the location.href ? Any ideas?
                  1 2 Previous Next