开发者

Sorting datatable column by day name

I have a datatable with day name column. I want to sort this column by 开发者_如何学JAVAday 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜