Sort a tableview on a column

Hi Experts,
My question is I want to sort the tableview in the sales order screen containing the items based on a column.Now what standard has provided is that u can only sort on Item no or the Product and not on other fields which are not the key fields.How do I sort on any other column present in the table except the key columns.
Thanks,
Ashish.
P.S.: I am working in SAP CRM 2007

Hi,
It can be definitely done like this.
  TRY.
      me->typed_context->CONTEXT NODE->collection_wrapper->sort( iv_attr_name
                                                                                = 'XXX'
                                                                    iv_sort_order    = 'A' ).
      CATCH cx_crm_cic_parameter_error.
ENDTRY.
But the place where it is implemeted is important as some methods like DO_PREPARE_OUTPUT get triggered for all the Server Events.
I prefer doing it in DO_INIT_CONTEXT rather than ON_NEW_FOCUS as it may not exist for some views and DO_INIT_CONTEXT  triggers only once by default.
Regards,
Masood Imrani S.

Similar Messages

  • How to display the sorting arrows in the table column header

    Hi
    I am doing a sorting for some columns from the click of the table column headers, In Developer studio, we are able to view the up and down arrows, I need that also to be made visible at run time, so that the user knows that there exists sorting based on that particular column. Is there any other way of doing it ? I cant place more than one control on the header or wrap the text to two lines..also. please clarify. thanks

    I assume you are using NW 04.
    The table column header contains a IWDCaption element which may display an icon and a text. See property IWDCaption.imageSource.
    The table tutorial might also be helpful.
    Armin

  • Sorting records based on multiple columns

    Hi All,
    Please provide SQK query to sort the records in multiple columns
    based on NON NULL and NULL values.
    SID SNUMBER UNIT COUNTRY  STATE
    0 M14762 DE 0
    NULL    NULL            NULL    NULL
    0 990 GB
    0 M14704 IE 0
      M14767 IE 0
    0 M14704 FR 0
    0 M15351 990 GB
              FR 0
    0 D10693 800 GB 0
    NULL    NULL            NULL    NULL
    0 D10693 800 GB 0
    If all column values are NOT NULL those records should come first.
    If first column(SID) values are NOT NULL those records should come next.
    If second column(SNUMBER) values are NOT NULL those records should come next.
    If third column(UNIT) values are NOT NULL those records should come next.
    If fourth column(COUNTRY) values are NOT NULL those records should come next.
    If fifth column(STATE) values are NOT NULL those records should come next.
    If all the column values are NULL those records should come last.
    The output should be like this.
    SID SNUMBER UNIT COUNTRY  STATE
    0 D10693 800 GB 0
    0 D10693 800 GB 0
    0 M14762 DE 0
    0 990 GB
    0 M14704 IE 0
    0 M14704 FR 0
    0 M15351 990 GB
      M14767 IE 0
              FR 0
    NULL    NULL            NULL    NULL
    NULL    NULL            NULL    NULL
    Please help me.
    Thanks.

    Hi,
           For Your Requirement,
    SELECT COALESCE (SID, snumber, unit, country, state) SID,
           (CASE
               WHEN SID IS NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN unit
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND country IS NOT NULL
               AND unit IS NOT NULL
               AND state IS NOT NULL
                  THEN unit
               WHEN SID IS NOT NULL AND snumber IS NOT NULL
                  THEN snumber
               WHEN SID IS NULL
               AND snumber IS NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN unit
               WHEN SID IS NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN country
               WHEN SID IS NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NULL
               AND state IS NULL
                  THEN unit
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN snumber
               WHEN SID IS NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN country
                  when sid is not null and snumber is null and unit is null and country is not null and state is not null then country
               ELSE NULL
            END
           ) snumber,
           (CASE
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN unit
               WHEN SID IS NULL AND snumber IS NOT NULL AND unit IS NOT NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN unit
               WHEN SID IS NOT NULL AND snumber IS NOT NULL AND unit IS NOT NULL
                  THEN unit
               WHEN SID IS NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN country
                  when sid is not null and snumber is null and unit is null and country is not null and state is not null then state
               ELSE NULL
            END
           ) unit,
           (CASE
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NULL
                  THEN country
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
                  THEN country
               WHEN SID IS NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               ELSE NULL
            END
           ) country,
           (CASE
               WHEN SID IS NOT NULL
               AND snumber IS NOT NULL
               AND unit IS NOT NULL
               AND country IS NOT NULL
               AND state IS NOT NULL
                  THEN state
               ELSE NULL
            END
           ) state
      FROM tablx;
    Cheers...

  • Problem - Sort output in table (multiple columns)

    Dear all,
    First of all - Best wishes for 2008.
    I probably have an easy matter, but i can't figure it out, and on this forum very little is mentioned about the sort operator, so therefore this new post.
    I have a dashboard with some input fields (dropdown boxes).
    I have a table (as result of query) and this works fine. The table consists of several columns. (so far no rocket science).
    Generally the structure of the table is like:
    IM SBU | App. Request key | App. Request | etc....
    I want the IM SBU colum to be sorted (assending or decending doenst matter).
    But somehow the second column is the one where the data is sorted (standard).
    My guess this happends because its a key value? or its because it starts with an A (and the other with and I).
    So i insert the sort opperator, add an object (IM SBU) and select up. Then from that opperator i create a table.
    This results in a table with just 1 column (IM SBU).
    So i tried several things.
    I tried to sort on the IM SBU key (this gives the same result).
    I added all colums as an object of the sort opperator...but this still gives the same result of just 1 column.
    Any ideas?
    Regards.
    Bart

    Dear all.
    I'm wondering if  anybody else experienced errors with the sort and the amount of columns shown in a table????
    In general i have a query and want a table as output with 8 columns (sorted by 1 object). I figured out the following and will demonstrate it with 4 situations.
    Situation1 (auto fit table without sort)
    In the properties of the table i select 'frame style'= 'Primary frame' and "fit content" = 'auto'. I run the dashboard and the content of the query is good. All columns are shown and the chart width is auto determined.
    Situation 2 (auto fit table with sort)
    I want to sort on 1 object, so from query i insert a sort (select object), and from sort i create table. Then i select 'frame style'= 'Primary frame' and "fit content" = 'auto'. I run the dashboard and the content of the query is NOT good. I just get to see 1 column. But i selected 8 columns.
    Situation 3 (actual fit table with sort)
    I want to sort on 1 object, so from query i insert a sort, and from sort i create table. Then i select 'frame style'= 'Primary frame' and select "fit content" = 'actual size'. I run the dashboard and the content of the query is good (but not what i want). I get to see all 8 columns. But the table is smaller than i want. I doenst auto fit.
    Situation 4 (fit width table with sort)
    I want to sort on 1 object, so from query i insert a sort (select object), and from sort i create table. Then i select 'frame style'= 'Primary frame' and "fit content" = 'fit width'. I run the dashboard and the content of the query is NOT good. I just get to see 1 column (again). But i selected 8 columns.
    Any suggestions?
    Any known work arounds?
    Or is this an error in VC and should i request a note?
    Regards.
    Bart

  • Can numbers sort by more than one column? How?

    Can numbers sort by more than one column? How?

    Open the "Sort & Filter" options:
    Then add columns.  You can set sort ASCENDING or DESCSANDING then drag the items to set the which column is sorted first

  • Sort by clicking on the column heade with LIFO

    Good morning!
    I would like to sort by last entry is first (LIFO) in my report.
    To do that, I have to un check in sort:
    Home>Application Builder>Application ***>Page 1>Report Attributes*(Otherwise APEX shows: "Your query can't include an "ORDER BY" clause when having column heading sorting enabled.")*
    When I follow the APEX suggestion, my report lost feature to sort by clicking on the column header.
    I still want to keep sorting ability on any column just by clicking on the column header.
    Thanks in advance,
    Sam

    Sam,
    First remove the order by clause from your query and then try to set the sorting using the sort sequence. Thanks.
    Regards,
    --Manish                                                                                                                                                                                                                                                                                               

  • Sort a tableview column containing a date

    This is my second request to find more info on handling dates javafx2, no replies to the first so am trying again.
    I am a relative "newby" to java, FX2 has so many compelling features I really want to use it.
    Displaying and sorting on dates seems like such a fundamental requirement that I am surprised that I can't find any examples anywhere on handing dates in a tableview.
    This would be so easy to do in Cocoa with the "date formatter" so apologies if I am missing something obvious.
    If I use a formatted date the column sorts on the text not on the actual date.
    eg. starting with
    06/01/2012
    08/01/2011
    07/01/2012
    sorting ascending gives
    06/01/2012
    07/01/2012
    08/01/2011
    and descending
    08/01/2011
    07/01/2012
    06/01/2012
    both wrong!
    Same issue if I use a calendar in the cells.
    Hope the answer is not to have a separate column for day, month and year.

    Hi wornish,
    TableView sort can be customized as per our needs. A sample example of Date is given here:
    Currently Let's suppose that you are displaying data of "Date" in String form using SimpleDateFormat class.
    TableView<Date> view = new TableView<Date>();
    TableColumn<Date,String> col = new TableColumn<Date,String>("Date");
    col.setComparator(new Comparator<String>(){
         @Override
         public int compare(String t, String t1) {
            try{
              SimpleDateFormat format =new SimpleDateFormat("MM-dd-YYYY");
              Date d1 =format.parse(t);               
              Date d2 = format.parse(t1);
              return Long.compare(d1.getTime(),d2.getTime());
            }catch(ParseException p){
                 p.printStackTrace();
            return -1;
    col.setCellValueFactory(new Callback<CellDataFeatures<Date, String>, ObservableValue<String>>() {
         @Override
         public ObservableValue<String> call(CellDataFeatures<Date, String> param) {
              SimpleDateFormat format = new SimpleDateFormat("MM-dd-YYYY");
              return new SimpleObjectProperty(format.format(param.getValue()));
            Thanks
    Narayan

  • Is there a way to sort a table by a column of scripture references?

    Here's some sample data:
    Book
    Reference
    Genesis
    1:2
    Genesis
    1:26
    Genesis
    1:6-19
    Genesis
    1:6-8
    Genesis
    12:1
    Genesis
    12:3
    Genesis
    2:2
    My table has certain references from all the books of the Bible (sans Apocrypha), so it's prohibitively hefty, but this gives you a few of my problems:
    It's really hard to sort by books, as they weren't included in the canon in, um, alphabetical order. But I can get around that.
    The verses (the numbers after the colon in the Reference column) are sorted in A-Z style, which is where the bulk of my problem is:
    All chapters beginning with "1" will sort ahead of chapter 2... this is a problem.
    All verses that begin with a lower ordinal will precede any verse that begins with a higher one--in the example above, "26" sorts ahead of "6-19".
    It may be that I'm asking too much of Numbers' built-in sorting tool... any ideas on how I can straighten this out? Short of breaking the chapters and verses apart, of course... I have like 9,000 rows to this table and am not really keen on breaking that format up if I can avoid it, though I'm thinking I won't be able to.
    Thoughts?

    Hi Mikey,
    Numbers sorts numbers in numerical order, and text in 'alphabetical order'.
    You can sort books into the order they appear by adding a column containing a number equivalent to the book's position in the Book.
    Chapter and verse can be handled in several ways:
    Separate book, chapter and verse into four columns. book in two columns (number in the first, name in the second), chapter (as a number) in the third, verse (as a number) in the fourth.
    A three stage sort, on book number, then on chapter number, then on verse number will then put everything back in the original order. Note that a 'three stage sort' is NOT the same as 'three single rule sorts'.
    First two columns as above, chapter and verse combined in column 3. This will require a change in your chapter:verse notation. Here are two possibilities:
    1. Use a numeric notation, replacing the colon with a decimal point. Add one or two leading zeroes to the verse part (after the decimal) to maintain three places after the decimal..
    2. Use text notation, retaining the colon separator. pad the chapter number and the verse number with leading zeroes to maintain three digits before and after the colon.
    (Three places are needed before the colon to allow for the 150 'chapters' in Psalms. Two will be sufficient after the colon unless there is a chapter with more than 99 verses. Unnumbered verses may be accommodated by appending a letter to the number for the past numbered verse (in the text notation), or by extending the decimal part by one digit (for up to nine unnumbered verses in sequence, or by two digits for sequences containing more then nine, but fewer that 100 unnumbered verses. I didn't do a search to determine which of these would be necessary.
    Either of the C&V notations above could be constructed from the 'standard' notation using a formula, and placed in a column which may be hidden, and used only for sorting.
    Regards,
    Barry

  • When I sort by date added in Column View in Finder, how can I make the most recent files appear at the top of the list?(Mavericks)

    In 10.8, when I sorted Finder by date added or date created in column view, the most recent files would appear at the top of the list. Currently, this happens as it should in every single view mode EXCEPT column view (which is pretty much the only view I ever use). Currently, I have a folder with over 2000 files in it that date back to 2011, so now I have to scroll for like ten minutes just te get to files that were most recently added. Who in their right mind would want to sort by last modified with the oldest result listed FIRST? Ridiculous. I can't figure this out. Any help?

    Thanks for the reply leroydouglas! Unfurtunately this doesn't cause the column to be ordered correctly either. After selecting this option, the files seem to be ordered by label, and the most recently added file is somewhere in the middle of the list. I'd like it to be at the top, and have other files/folders descend in retrochronological order by their add date.
    Any other input from the community would be greatly appreciated, even if it's just confirming that this is/is not expected behavior. I'd be super bummed to find out that this IS expected behavior, as it's really counterintuitive and extremely inconvenient.
    Thanks again!

  • Pivot table sorting with month_id and average column in BI publisher temp

    In my project we are using the Oracle BI analysis for creating reports in BI publisher.
    At first we are creating the report in OBIEE answers then using it as data model in BI Pub.
    My reporting table holds data like below:
    Month_Name Year Month_Id Compensation Emp ID
    JAN 2011 1000 50 1234
    FEB 2011 1001 60 1235
    We need to show the data in pivot format i.e period(concated month+year) in column and comepsation values as measure and emp id in rows.I also need to show percentage i.e sum(Compensation/no of selected of periods).
    For average in OBIEE pivot i have create one calulated item. But I can't sort the data(for periods with the month_id) as its spillting the average column also.
    How can i sort it? like JAN2011 FEB2011 MAR2011 in pivot
    also in BI pub this calculated item not showing correct value.
    Please help.

    Hi,
    You can achieve this requirement by sort order column based on the month number and year you can sort this criteria column.also by using time_key,if the time_key is in sequence.
    mark if helpful/correct...
    thanks,
    prassu

  • Table sort is not working for columns.

    Hi,
    I am using TableSort.java class. Followed https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/library/user-interface-technology/wd%20java/wdjava%20archive/developing%20with%20tables%20in%20web%20dynpro.pdf
    to create the action and assigned that to onSort event for the table. When I run, I see the ascending-descending icons besides the columns, but nothing happens when I click them. Here is the context.
    Context
    l
    l
    l ---User_Table
             > Email
             > Name
            |
             > Office
    Here Name is a custom string (last name, first name). Also office is a custom string (office1, office2, ...etc).
    Edited by: srinivas M on Feb 8, 2009 6:03 AM
    Edited by: srinivas M on Feb 8, 2009 6:03 AM

    Hi Srinivas,
      If you want to do an initial sort. You have to add the following method to the TableSorter class.
    public void initialSort(String columnId, IWDNode dataSource) {
              // find the things we need
              String direction = WDTableColumnSortDirection.UP;
              IWDTableColumn column = (IWDTableColumn) table.getView().getElement(columnId);
              NodeElementByAttributeComparator elementComparator = (NodeElementByAttributeComparator) comparatorForColumn.get(column);
              if (elementComparator == null){
                   //not a sortable column
                   column.setSortState(WDTableColumnSortDirection.NOT_SORTABLE);
                   return;
              // sorting
              elementComparator.setSortDirection(WDTableColumnSortDirection.valueOf(direction));
              dataSource.sortElements(elementComparator);
    In your wdDoModifyView() after initializing the tablesorter class you have to call the above method.
    if (firstTime) {
                IWDTable table = (IWDTable) view.getElement("Table");
                wdContext.currentContextElement().setTableSorter(
                   new TableSorter(table, wdThis.wdGetSortAction(), null));
                      wdContext.currentContextElement().getTableSorter().initialSort("Your Column ID", wdContext.nodeUser_Search_Results());
    Can you double check in your code if the table is bound to the node "User_Search_Results" and not "User_Table". If the table is bound to the "User_Table" then the sort will not work since in the code you are sorting the node "User_Search_Results".
    If you want to implement sort on only one column you can use the alternate constructor for the TableSorter class.
    TableSorter(IWDTable table, IWDAction sortAction, Map comparators, String[] sortableColumns)
    You have to give a String array of columns that need to be sort enabled.
    Regards,
    Sanyev

  • Is it possible to sort by dates in a column?

    I have a column of dates and would like to sort either ascending or descending, but Numbers sorts by the first number.  Is there any trick to getting it to sort dates?

    Janice,
    I would guess that if Numbers is only using the first number to sort then it may not think the information you entered is a valid date.
    Here is an example showing that Number does not think my last entry is a valid date:
    Column A has no special formatting.  In this case when I enter a date Numbers right justifies it when it recognizes the entry as a valid date.  In the event Numbers does not recognize the entry as valid it left justifies it.  Do you see any entries that are not valid dates?

  • Sort Order for a VARCHAR2 Column

    Hello Everyone,
    This is probably quite simple, however I cannot see it. I am trying to sort on a varchar2 column that has numbers, text, dashes, tildes, carets and underscores which are mixed to compose a wire number. I have come up with an order by that changes the sort order from alpha to numeric satisfying one portion of the requirement.
    select wirenbr,fromitem "from",frompin,diagnbr,sht,toitem,topin,effect
    from acft_wires
    order by decode(to_char(nvl(length(translate(wirenbr,'A1234567890','A')),0)),'0',lpad(wirenbr,18),wirenbr);
    The select returns:
    1
    2
    3
    20
    21
    200
    201
    1000
    A
    ADT1
    AEN1
    AE1
    AE9
    AFA
    B
    1A
    2U7230A-ZZ
    2000A
    213-22
    22X100A20
    220-11
    The customer preferred sort looks like:
    1
    2
    3
    10
    10A
    11
    200
    201
    201-01
    202
    1000
    1000A
    1001
    I will build a shrine in my hall of honor to this forum if someone can point me in the right direction on how to solve this problem.
    Thanks everyone for your help.

    ok, start with this
    order by
    translate(substr(wirenbr,1,1),'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','0000000000ZZZZZZZZZZZZZZZZZZZZZZZZZZZ')
    , nvl(length(substr(wirenbr,1,instr(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','1234567890XXXXXXXXXXXXXXXXXXXXXXXXXXX'),'X')-1)),length(wirenbr))
    , to_number(translate(wirenbr,'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-','123456789000000000000000000000000000'))
    First, all that start with number go to the beginning and all that start with a letter go to the end.
    Next, sort by the length of the first numerical part, as per Al's first solution.
    Next, sort by the numerical part.
    I started getting what I think is the right sort by that point. However, I think that you'll also have to add
    stuff to sort by the alpha part, mine was
    , NVL(RTRIM(LTRIM(wirenbr,'0123456789'),'0123456789'),0)
    The biggest problem I see is all of the different number-letter-number
    number-letter-number-letter formats. How many levels of recursion you'll have to go through to get it perfectly sorted, could you have ZZ999ZZ99Z9Z9Z9Z99?
    Any ideas for breaking this value up?

  • Update a list item based sort order of created by column value

    HI
    using powershell script how to sort a list column before update a list  item.
    here i created a document library and uploaded some documents and update ProcessNo column based sort order of created column
    value.
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:91" $listName = "Courts"
    Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    $list = $web.Lists[$listName] 
    $items = $list.items
    Go through all items
    foreach($item in $items)
    $item["ProcessNo"] = 1
    $item.Update()
    $web.Dispose()

    Hi,
    According to your description, my understanding is that you want to sort the list items order before updating items using PowerShell.
    I suggest you can use the Sort-Object command to sort the list items.
    Here are some detailed articles for your reference:
    Better SharePoint Lists and List Items in PowerShell
    Sort-Object
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Sorting a Collection with dynamic columns using a custom compare function for multiple columns

    I need help and ideas on how to sort a ListCollectionView.  My problem is complicated by 3 requirements-
         1. The column values contain HTML tags that needs to be removed before sorting (use custom compareFunction to strip HTML)
         2. The columns are dynamic, so dataField names are not known at compile time (need a single compareFunction for all columns)
         3. The data is used in an AdvancedDataGrid so multi-column sorting is required
    I have figured out how to solve any 2 of the 3 requirements.  However, I am having difficulties supporting all 3 requirements.
    Any help or ideas would be greatly appreciated.  Thanks.

    After playing with this some more I think I've figured out a solution.  This seems to work in initial testing.  Also, there is not a need to capture the current sort column in the headerRelease event which many offered solutions suggested.  Another benefit to this solution is that keyboard initiated sorting is handled also.  Whereas the headerRelease event is only triggered by a mouse click on the column header and special handling is required if the user uses the keyboard to access the column header.
    One point that I don't understand is how ascending/decending order is determined.  Behavior seems to be different between a single SortField versus multiple SortFields.  Notice how the compareResults are handled for the different situations.  Anyone out there know why???
     private function colSortCompareFunction(obj1:Object, obj2:Object, fields:Array = null):int{
         var compareResults:int = 0; 
         var newObj1:Object = new Object(); 
         var newObj2:Object = new Object();
          // should not be a condition that is met   
         if (_dataProviderDetails.sort.fields == null)     {
              var s:Sort = new Sort(); 
              var f:Function = s.compareFunction; 
              return f.call(null, obj1, obj2, fields);     }
         // when a single column is selected for sorting   
         else if (_dataProviderDetails.sort.fields.length == 1)     {
              var firstFld:SortField = _dataProviderDetails.sort.fields[0];
              newObj1[firstFld.name] = stripHTML(obj1[firstFld.name]as String);          newObj2[firstFld.name] = stripHTML(obj2[firstFld.name]
    as String);
              compareResults = ObjectUtil.compare(newObj1[firstFld.name], newObj2[firstFld.name]);
               return compareResults;     }
         // when multiple columns are selected for sorting   
         else       {
              for each (var fld:SortField in _dataProviderDetails.sort.fields)          {
                   newObj1[fld.name] = stripHTML(obj1[fld.name]
    as String);               newObj2[fld.name] = stripHTML(obj2[fld.name]
    as String);
                   compareResults = ObjectUtil.compare(newObj1[fld.name], newObj2[fld.name]);
                    if (compareResults != 0)               {
                        if (fld.descending)                    {
                             return compareResults * -1;                    }
                        else                      {
                             return compareResults;                    }
               return compareResults;     }
    Does anyone see any problems with this solution?
    NOTE:  stripHTML(String) is a simple function using regular expression to remove HTML tags.
    Thx

Maybe you are looking for

  • Why won't my iPhone 5s running iOS 7.0.2 show up in iTunes?

    I recently purchased an iPhone 5s for T-Mobile. Yesterday, I got my number switched over at the T-Mobile retail store, and I brought it home and connected it to my laptop with the current latest version of iTunes (11.1.11 64-bit). After I connect it,

  • Calendar on iPhone 3G iOS 4.1 still very slow to open

    Since I went from iOS 3 to the terrible 4 also my iPhone 3G has been very slow. The biggest problem however seems isolated: when I open the Calendar app, it takes a very long time for it to open. Initially it opens as quick as it used to, however the

  • Fonts (Libraries)recognized problem

    Wow is it me or has this place change bigtime since my last visit? lol I use Suitcase fusion for my fonts management fyi Okay I have divided up my library of fonts into 5 different libraries (an easier locating method for me) But when I open PsCS5 it

  • Genius is unavailable for the song ...

    SInce late in 2010 my iTunes does not seem to be able to use any new music that I have imported to create a Genius. Older, previously imported, songs work fine (if they are recognized by the store, etc) but the new ones do not. Have have tried: reset

  • Unique constraint deployable=false

    I am new to OWB. We are using client version 10.1.0.2.0. We have a mapping where the target table (a cube) is set to update/insert, match by a unique constraint which comprises two values. A non-unique index on the cube comprises the same two values.