1

I have an editable column definition that looks like this...

    {
        name: 'recType',           
        label: 'recType',           
        index: 'recType',                           
        width: 100, 
        fixed: true,  
        keys:  true,     
        editable: true, 
        edittype: "select",  
        editoptions: {value: rectypelist}, 
        stype: 'select',
        formatter: 'select'
    }

Note: "rectypelist" is a list of key:value pairs...e.g.,

    1:apple
    4:pear
    2:orange
    3:banana

I need to be able to sort this column by the listbox entry's value (i.e., which is already correctly displayed in the column).

As it is configured, above, the sort is performed upon the listbox entry's "key", rather than the entry's "value" (the entry's "value" is what actually displays in the grid).

-So, therefore, when the user sorts the column they do not received the expected behavior.

QUESTION: How can I configure this column definition so that the sort is performed on the listbox entry's "display" value, rather than the "key" value?

Thanks for any help

sairn
  • 461
  • 3
  • 24
  • 58

1 Answers1

1

Here's how I solved the issue...

Well, apparently when your column is defined as dropdown/listbox (containing rows of key:value pairs)...

like,

    1:rectypeA
    4:rectypeB
    2:rectypeC
    3:rectypeD

...then, in the column definition, you need assign a function to the "sorttype" parameter that will return the value you want to sort on... (in this case I want to use the "value" from the "key:value" pair)...

--Since I don't want my column sorted by the "key" (i.e., this is the problem I am trying to solve!), I apparently have to use a function to return the "value" that corresponds to the "key".

In the example, below, I've created a map called "rectypes" that contains key:value pairs.

--In the function, I simply use the "rectypes" map to extract and return the value (associated with the "key") that I want used in the sort

i.e.,

    -
    -
    -
    {
        name: 'recType',           
        label: 'recType',           
        index: 'recType',                                               
        width: 100, 
        fixed: true,  
        keys:   true, 
        sortable:true,  
        //...the function below returns the VALUE of 
        //   the KEY:VALUE pair that is to be used for the sort
        sorttype: function (cellvalue ) {return rectypes[cellvalue];},
        editable: true, 
        edittype: "select",  
        editoptions: {value: rectypelist}, 
        stype: 'select', 
        formatter: 'select'
    },    
    -
    -
    -

NOTE: "cellvalue" is supplied auto-magically. In the example I created a map called "rectypes" containing the "key:value" pairs that make it possible for me to extract and return the value that I want to be used for sorting.

sairn
  • 461
  • 3
  • 24
  • 58