Total Pageviews

2015/03/11

[AngularJS] How to set 1000 separator in ng-grid

Problem
I am using AngularJS to implement data grid as bellows:

Here has the code snippet:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
$scope.dbm100eFormGrid2 = {
        data : 'dbm100eFormGrid2Data',
        selectedItems: $scope.grid2SelectedRow,
        columnDefs : [
                      { field : 'budgetCode',  displayName : '預算別', 
                        width: 150, cellClass: 'text-left'},
                      { field : 'debtCode',    displayName : '債務別', 
                        width: 150, cellClass: 'text-left'}, 
                      { field : 'issueAmount', displayName : '發行額', 
                        width: 170, cellClass: 'text-right'}, 
                      { field : 'realAmount',  displayName : '實收額', 
                        width: 170, cellClass: 'text-right'},
                      { field : 'debtName',    displayName : '利率%',  
                        width: 170, cellClass: 'text-left'}],
        enableColumnResize :true,
        i18n:'zh-tw',
        multiSelect : false
};

If I would like to add 1000 separator to issueAmount(發行額) and realAmount(實收額) column, how to do it?


Solution
Just add cellFilter:'number' to issueAmount(發行額) and realAmount(實收額) column definition.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
 $scope.dbm100eFormGrid2 = {
         data : 'dbm100eFormGrid2Data',
         selectedItems: $scope.grid2SelectedRow,
         columnDefs : [
                       { field : 'budgetCode',  displayName : '預算別', 
                         width: 170, cellClass: 'text-left'},
                       { field : 'debtCode',    displayName : '債務別', 
                         width: 170, cellClass: 'text-left'}, 
                       { field : 'issueAmount', displayName : '發行額', 
                         width: 170, cellClass: 'text-right', cellFilter: 'number'}, 
                       { field : 'realAmount',  displayName : '實收額', 
                         width: 170, cellClass: 'text-right', cellFilter: 'number'},
                       { field : 'debtName',    displayName : '利率%',  
                         width: 170, cellClass: 'text-left'}],
         enableColumnResize :true,
         i18n:'zh-tw',
         multiSelect : false
 };
  
  

Check the result :


Reference
[1] https://github.com/angular-ui/ng-grid/wiki/Defining-columns

No comments: