Sadeghbayan
Sadeghbayan

Reputation: 1163

Translate Ui-grid Angular

I'm trying to translate Ui-grid in angular but i can't . i just want to translate columnDefs .
here is my controller :

 $scope.gridOptions = {

        enableSorting: true,
        columnDefs: [

                  { name: 'نمایش', cellClass: "editCell", cellTemplate: '<i id="editBtn" tooltip-placement="left" tooltip="نمایش درخواست" class="fa fa-eye" ng-click="getExternalScopes().editUser(row.entity.RequestCode)" ></i>', headerClass: 'JobHeader' },

                   {
                       name: 'کد شهر',  headerClass: 'cityHeader', field: 'CityCode', editableCellTemplate: self.editableCellTempate, 
                       enableCellEdit: true
                   },
                    { name: 'کد امور', field: 'RgnCode' },
        { name: 'شماره درخواست', field: 'RequestCode' },

        ],


    };   

i want to translate name in columnDefs

Any idea ?

Upvotes: 4

Views: 3916

Answers (4)

saral
saral

Reputation: 81

Use displayName and $translate.instant('...'):

{
   name: 'CityCode',
   displayName: $translate.instant('CityCode'),
   headerClass: 'cityHeader',
   editableCellTemplate: self.editableCellTempate, 
   enableCellEdit: true
}

Upvotes: 0

ddsultan
ddsultan

Reputation: 2297

I used {field:'id', displayName:'ID_TRANSLATION_KEY', headerFilter:'translate'}. It works like usual template translation. Only problem with your solution you may be losing default sorting functionality offered by the component (have to create your own) when you use headerCellTemplate. I think this may help someone.

Upvotes: 6

PaulL
PaulL

Reputation: 6650

If you want to manually translate it, use name as the fieldname in your data, and then set displayName to whatever you want.

If you want to do on-the-fly translation using angular-translate, then as @YOU said.

Upvotes: 1

YOU
YOU

Reputation: 123881

Use

  • cellFilter:'translate' for cell,
  • headerCellFilter:'translate' for header
  • footerCellFilter: 'translate' for footer

in colummDefs

Upvotes: 7

Related Questions