1

Is there a way to combine two fields into one field in angular ui grid?

I tried the below code, the case manager part worked but the client part is not working

CaseServices.getCases().then(function (response) {
            $scope.gridOptions.columnDefs = [
          { name:'Title', field: 'Title' },
          { name:'Case Manager', field: 'Case_x0020_Manager.Title' },
          { name:'Client', field: 'Client.FirstName' + 'Client.Title'},

        ],
            $scope.gridOptions.data = response.d.results;
        });

I saw in an example that we can build our own functions like below

columnDefs: [
          { name:'firstName', field: 'first-name' },
          { name:'1stFriend', field: 'friends[0]' },
          { name:'city', field: 'address.city'},
          { name:'getZip', field: 'getZip()', enableCellEdit:false}
        ],
        data : [      {
                           "first-name": "Cox",
                           "friends": ["friend0"],
                           "address": {street:"301 Dove Ave", city:"Laurel", zip:"39565"},
                           "getZip" : function() {return this.address.zip;}
                       }
                   ]

But since I am getting response from ajax call, I am not sure how to modify the data part ($scope.gridOptions.data = response.d.results;)

Can someone help on any one of these? as it will solve the purpose

3
  • Your ajex results I guess are just an array. After you get it back, you can modify it anyway you want with plain ol' JS .map, .filter, etc. You bind that modified array to your grid and you should have what you want. Commented Jan 18, 2017 at 12:15
  • Thanks Tim. isn't there some other way in angular ui grid other than parsing through array and reconstructing it? Commented Jan 18, 2017 at 12:33
  • There might be. But running a standard filter or map on an array to transform a list or grid is very standard practice. It only takes a line or two of code, and if you're dealing with this sort of thing on any kind of regular basis, is very (very) worth knowing how to do. Commented Jan 18, 2017 at 13:10

1 Answer 1

1

There are two ways to do this

Modifying the object array

$.each(response.d.results,function(){
            this.ClientName = this.Client.FirstName + " " + this.Client.LastName;  

         });

Using CaseTemplate feature available in angular ui grid (recommended)

$scope.gridOptions.columnDefs = [
                  { name:'Title', field: 'Title' },
                  { name:'Client', field: 'Client', cellTemplate:'<div>{{row.entity.Client.FirstName + " " + row.entity.Client.Title }}</div>'},
                ],
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.