views:

17

answers:

1

Hi,

I have a datatable with day name column. I want to sort this column by day name e.g. if I have [Friday, Monday,Sunday] sorting should return [Monday ,Friday, Sunday] (ascending) and [Sunday,Friday, Monday] (descending).

I tried to use custom sorting but I wasn't able to represent my custom order.

Do you have ideas ?

Thanks

A: 

I found a solution for my problem. I created a hidden column with numeric values. The sorting will be based in this column. This is the custom sort function

 // Custom function to sort  Column  by another Column
   var mysortFunction = function(a, b, desc) {
             // Deal with empty values
             if(!YAHOO.lang.isValue(a)) {
                 return (!YAHOO.lang.isValue(b)) ? 0 : 1;
             } else if(!YAHOO.lang.isValue(b)) {
                 return -1;
             }

             //  compare column values
             var comp = YAHOO.util.Sort.compare;
             var compState = comp(a.getData("myhiddenColumn"), b.getData("myhiddenColumn"), desc);
             return  compState;
   };

And the column defs :

    var myColumnDefs = [
           { key: "A", sortable:true,hidden:true },
           { key: "columnToSort",label:"ABC",  sortable:true, sortOptions: { sortFunction: mysortFunction }
    { key: "myhiddenColumn", sortable:true, hidden:true  }
    }

];

Hope this helps

Eli