0
 var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.importer']);

 app.controller('MainCtrl', ['$scope', '$http', '$interval', function ($scope, $http, $interval) {
  $scope.data = [];
  $scope.gridOptions = {
  enableGridMenu: true,
  data: 'data',
  importerDataAddCallback: function ( grid, newObjects ) {
  $scope.data = $scope.data.concat( newObjects );
  },
  onRegisterApi: function(gridApi){ 
  $scope.gridApi = gridApi;
  }
 };
 }]);

Suppoese this is the json file

[{
  "Name":"John Smith",
  "Gender":"male",
  "Company":"TestIcon"
 },
 {
  "Name":"Jane Doe",
  "Gender":"female",
  "Company":"FastTruck"
 }]

Now i wll get the the grid having columns Name, Gender and Company.

Now how will i dynamically change the Grid column names : Like I want FirstName instead of Name

Guys Please help me in sorting this

4
  • Why you want to change the json? Commented Apr 26, 2015 at 6:44
  • There is a case in my application, where i have predefined template like My template headers are FirstName, Gender,CompanyName, now i just want to map this template to different names used by different users in their json. Commented Apr 26, 2015 at 6:48
  • If you don't know before-hand what column names your users will have, you will need to have a way for them to choose the mapping. Or if you can do a best-guess you could create a pre-defined mapping dictionary, like 'name', 'firstName', 'name1', etc., all map to your 'FirstName' column definition. Commented Apr 26, 2015 at 15:21
  • Yes I will give the user, a option to map their column to my columns of predefined template. Now my problem is , after mapping how will i dynamically change the grid headers column. Commented Apr 27, 2015 at 5:50

1 Answer 1

0

Supposing the name of your json object is gridJson:

var newGrid = gridJson.map(function(object) {
  object.FirstName = object.Name;
  delete object.Name;
  return object;
}

Array.map documentation

Sign up to request clarification or add additional context in comments.

Comments

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.