1

I am using ng-grid from following link:http://angular-ui.github.io/ng-grid/

My MVC Controller function return data in json format which includes date like this

: "RunDate":"\/Date(1439577000000)\/","RunDate":"\/Date(1441391400000)\/" etc....

My View:

<div ng-grid="gridOptions" style="min-height:420px"></div>

My Grid options in js:

$scope.gridOptions = {
        data: 'myData',
        enablePaging: true,
        showFooter: true,
        columnDefs: [{ field: "RunDate", displayName: "Run Date", width: 120, cellFilter: "date:'yyyy-MM-dd'" }],
        totalServerItems: 'totalServerItems',
        pagingOptions: $scope.pagingOptions,
        filterOptions: $scope.filterOptions
    };

I want date to be display in this format:06/April/2015

Can anybody help me with this???

3 Answers 3

2

You need to apply custom filter on you variable while binding data. Do use cellTemplate of column level.

Code

 $scope.gridOptions = {
 data: 'gridData',
 columnDefs: [{
         field: 'RunDate',
         displayName: 'Run Date',
         cellTemplate: '<span> {{row.entity.RunDate | date:\'dd-MMM-yyyy\'}}</span>',
     },
     ....
 ]
 });
13
  • @MariaPithia row.entity contains row level data Commented Apr 8, 2015 at 5:08
  • oh ok thanks.what options you would suggest me for displaying data in grid?? Commented Apr 8, 2015 at 5:23
  • put the code given by me, to your columnDefs of ng-grid option Commented Apr 8, 2015 at 5:25
  • pankaj can you suggest me some option instead of ng-grid like i am thinking for kendo grid (with script only)?? Commented Apr 8, 2015 at 6:10
  • 1
    the link you have given there it is saying smart table.what would you say about it?? Commented Apr 8, 2015 at 6:32
2

Use Angular date filter, like this:

{{row.entity.RunDate | date:'dd-MMM-yyyy'}}
1
1

You need to change the date formatting on your gridOptions The correct date format you need is

dd/MMM/yyyy

 $scope.gridOptions = {
        data: 'myData',
        enablePinning: true,
        columnDefs: [
                     { field: 'RunDate',displayName: 'Run Date', cellFilter: 'date:\'dd/MMM/yyyy\'' },
                   ]
    };
   ...........
});

Check this link for an example

0

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.