如何格式化要显示在 ng-grid 中的日期,它是来自 json 中服务器的 returns?
How to format the date to be display in ng-grid which is returns from server in json?
我正在使用来自以下 link:http://angular-ui.github.io/ng-grid/
的 ng-grid
My MVC Controller function return data in json format which includes
date like this
:
"RunDate":"\/Date(1439577000000)\/","RunDate":"\/Date(1441391400000)\/"
等......
我的看法:
<div ng-grid="gridOptions" style="min-height:420px"></div>
我在 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
};
我希望日期以这种格式显示:06/April/2015
谁能帮我解决这个问题???
使用Angular date filter,像这样:
{{row.entity.RunDate | date:'dd-MMM-yyyy'}}
您需要更改 gridOptions
上的日期格式
您需要的正确日期格式是
dd/MMM/yyyy
$scope.gridOptions = {
data: 'myData',
enablePinning: true,
columnDefs: [
{ field: 'RunDate',displayName: 'Run Date', cellFilter: 'date:\'dd/MMM/yyyy\'' },
]
};
...........
});
查看此 link 示例
您需要在绑定数据时对您的变量应用自定义过滤器。请使用列级别的 cellTemplate
。
代码
$scope.gridOptions = {
data: 'gridData',
columnDefs: [{
field: 'RunDate',
displayName: 'Run Date',
cellTemplate: '<span> {{row.entity.RunDate | date:\'dd-MMM-yyyy\'}}</span>',
},
....
]
});
我正在使用来自以下 link:http://angular-ui.github.io/ng-grid/
的 ng-gridMy MVC Controller function return data in json format which includes date like this
:
"RunDate":"\/Date(1439577000000)\/","RunDate":"\/Date(1441391400000)\/"
等......
我的看法:
<div ng-grid="gridOptions" style="min-height:420px"></div>
我在 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
};
我希望日期以这种格式显示:06/April/2015
谁能帮我解决这个问题???
使用Angular date filter,像这样:
{{row.entity.RunDate | date:'dd-MMM-yyyy'}}
您需要更改 gridOptions
上的日期格式
您需要的正确日期格式是
dd/MMM/yyyy
$scope.gridOptions = {
data: 'myData',
enablePinning: true,
columnDefs: [
{ field: 'RunDate',displayName: 'Run Date', cellFilter: 'date:\'dd/MMM/yyyy\'' },
]
};
...........
});
查看此 link 示例
您需要在绑定数据时对您的变量应用自定义过滤器。请使用列级别的 cellTemplate
。
代码
$scope.gridOptions = {
data: 'gridData',
columnDefs: [{
field: 'RunDate',
displayName: 'Run Date',
cellTemplate: '<span> {{row.entity.RunDate | date:\'dd-MMM-yyyy\'}}</span>',
},
....
]
});