Simon
Simon

Reputation: 1476

Angular grid reverse columns

We are using angular-grid to display a grid of dynamic columns. ie:

col1    col2   col3    col4   col5    col6   col7    col8   col9    colx

The columns are being returned in the correct order, however, angular grid is displaying them back to front.

colx    col9   col8    col7   col6    col5   col4    col3   col2    col1

Is there a way to reverse these columns. We cant use column destinations, as we have no idea how many columns will be returned.

Upvotes: 1

Views: 1054

Answers (2)

Kabb5
Kabb5

Reputation: 3870

You will need to define the columnDefs for your data set. You can do this with your dynamic columns by doing something like this:

$scope.myData = [
  {name: 'col1', value: 'abc'},
  {name: 'col2', value: 'def'},
  // etc.
  {name: 'colx', value: 'xyz'}
];

$scope.$watchCollection('myData', function (new_myData, old_myData) {
  angular.forEach(new_myData, function(item, index) {
    $scope.columnDefs[index] = {
      field: item.name,
      value: item.value
    };
  });
});

Upvotes: 0

Lajos Veres
Lajos Veres

Reputation: 13725

You should list them in the columnDefs in the correct order.

The related documentation: http://angular-ui.github.io/ng-grid/

If you don't know the columns before getting them, you can set this property after you received the data, based on for example the first row.

Upvotes: 1

Related Questions