0

Hoping this would be something someone would have encountered, using the ng-grid component for displaying data.

One of the column is a phone number. Is there an easier way to format phone as (123)-123-1234.

The ng-grid code looks like this,

 $scope.gridOptions = { data:'records',
        enableRowSelection:false,
        filterOptions: $scope.filterOptions,
        columnDefs:[
            {field:'phoneNumber', displayName:'Phone', width:80} 
        ]};
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
sathish_at_madison
  • 823
  • 11
  • 34

2 Answers2

0

Replace the }, at the end of the phonenumber field with the following

, cellTemplate: " ({{row.getProperty(col.field).substr(0, 3)}}) {{row.getProperty(col.field).substr(3, 3)}} - {{row.getProperty(col.field).substr(6,4)}}"

  • Please [format](http://stackoverflow.com/help/formatting) your answer to improve its readability. Any explanation of what the code is doing is also beneficial. – ryanyuyu Mar 10 '15 at 22:11
0

Here is one solution that worked. the information "row.getProperty(col.field)|phoneNumber", "phoneNumber " is coming in the JSON string. The code in controller goes something like this for the column

 $scope.gridOptions = { data:'records',
    enableRowSelection:false,
    filterOptions: $scope.filterOptions,
    columnDefs:[
        {field:'phoneNumber', displayName:'Phone', width:80,cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text>{{row.getProperty(col.field)|phoneNumber}}</span></div>'}} 
    ]};

In the html file the following code snippet.

<div id="controller" data-ng-controller="controller">
    <div class="gridStyle" ng-grid="gridOptions" width="100%"></div>
</div>
 <script type="text/javascript" src="/common/PhoneFormat.js"></script> 
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.js></script> 
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-resource.js"></script>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-touch.js"></script>
 <script type="text/javascript" src="/common/ng-grid.js"></script>
sathish_at_madison
  • 823
  • 11
  • 34