0

I am using AngularJs ui grid with grouping. The table is displaying fine but the problem I am facing is that the months sequence in the table is getting jumbled up. Please find my Plunker. In the table the Months are appearing in the jumbled up sequence 11-14, 05-15, 04-15, ... 02-15. But I need it in the sequence of 11-14, 12-14, 01-15, 02-15, 03-15, 04-15, 05-15. Can any one help me to fix it?

I am using the following for to get colDefs:

$scope.getColumnDefsForUiGrid = function(columns) {
     var colDef = [];
     colDef.push({
         name: 'mode',
         grouping: {
             groupPriority: 0
         },
         displayName: 'Type',
         enableCellEdit: false,
         width: '5%'
     });
     colDef.push({
         name: 'service',
         displayName: 'Catg',
         enableCellEdit: false,
         width: '5%'
     });
     angular.forEach(columns, function(value, key) {
         colDef.push({
             name: key,
             displayName: value,
             enableCellEdit: true,
             aggregationType: uiGridConstants.aggregationTypes.sum,
             width: '5%'
         })
     });
     return colDef;
 };
5
  • Actually your ui-grid columns are in the exact same order than your $scope.columns. If you want to change the order, you can reorder this object. Commented May 13, 2015 at 8:16
  • How can I do it in getColumnDefsForUiGrid ? Commented May 13, 2015 at 8:20
  • I just want months in correct sequence order. Commented May 13, 2015 at 8:21
  • plnkr.co/edit/MkE58U9mefiRyMTC4Ohf?p=preview Now they are. But i'm not sure i get your problem. In your application does this column def is hard-coded too ? or are the column dynamic ? Commented May 13, 2015 at 8:31
  • It is dynamic. First I need to get mode and then service after that all the months should be displayed sequential order. After pushing Mode and Service into colDef, I have the flexibility to change the logic while looping through using angular.forEach(columns, function( value, key ). Can we something here in order to keep the sequence in the order? Commented May 13, 2015 at 8:49

1 Answer 1

1

Here is a workaround for your problem you can see it working on this plunker

$scope.getColumnDefsForUiGrid = function( columns ){
        var colDef = [];                        
        colDef.push({name: 'mode', grouping: { groupPriority: 0 }, displayName: 'Type', enableCellEdit: false, width: '5%'});
        colDef.push({name: 'service',  displayName: 'Catg', enableCellEdit: false, width: '5%'});

        //I split the monthColumns into an other array                      
        var monthCol = [];
        angular.forEach(columns, function( value, key ) {
              monthCol.push({name: key, displayName: value, enableCellEdit: true, aggregationType : uiGridConstants.aggregationTypes.sum, width: '5%' })
        });

        //I sort this array using a custom function
        monthCol.sort(function(a,b){
              a = a.displayName.split("-");
              b = b.displayName.split("-");
              if(a[1] < b[1]){
                  return -1;
              }else if (a[1] > b[1]){
                  return 1;
              }else {
                  if(a[0] < b[0]){
                     return -1;
                  }else{
                    return 1;
                  }
              }
        });

   //I concat the two array
   return colDef.concat(monthCol);
};
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, Accepted the Answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.