Tink Tink - 1 year ago 161
AngularJS Question

AngularJS : ui-grid field with a concatenation of two fields

I need a column in ui-grid which is a concatenation of two fields,say 'name' and 'address'. How can I achieve this?

Answer Source

Did you try this approach?


var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [
             {name: "Moroni", address: test1},
                     {name: "Tiancum", address: test2},
                         {name: "Jacob", address: test3},
                         {name: "Nephi", address: test4},
                         {name: "Enos", address: test5 }];

          row.getNameAndAddress = function(){
            return this.name + '-' + this.address;

    $scope.gridOptions = { 
        data: 'myData',
        columnDefs: [{field: 'name', displayName: 'Name'},
                     {field:'address', displayName:'Address'},
                     {field: 'getNameAndAddress()', displayName: 'Name and address'},


<body ng-controller="MyCtrl">
        <div class="gridStyle" ng-grid="gridOptions"></div>