MoonStorm / trNgGrid

A feature rich Angular grid using standard HTML tables.
MIT License
252 stars 66 forks source link

display-name="nameProviderFunction()" #89

Closed daniboomerang closed 9 years ago

daniboomerang commented 10 years ago

Hi, I am using angular-translate in order to internationalize my app. I need the column name to be translated. I can use angular-translate anywhere in the table, except for the column headers. In the previous version of trNgGrid, I use to do it like this and it worked:

thead tr th field-name="id"> ID /th th field-name="severity">{{ 'SEVERITY' | translate }}/th /tr /thead

But in 3.X.X this is not working anymore. We need to use "display-name" option:

thead tr th field-name="id"> ID /th th field-name="severity" display-name="{{ 'SEVERITY' | translate }}">/th /tr /thead

And this is not working anymore.

Having a look, i´ve realised that actually, display name doesn´t take $scope functions, it just take $scope variables.

So for example if I have my controller: $scope.testNameVariable = "testName"; th field-name="severity" display-name="{{ testNameVariable }}" /th Works Perfectly !!

But if I have something like this: $scope.testNameFunction = function (){ return "testName";}; th field-name="severity" display-name="{{ testNameFunction() }}" /th It doesn´t work !!

I wonder if this is the fact why I can´t use angular-translate....

Any clue on that??

Thanks a lot!

joebordes commented 10 years ago

Just FYI and in case it helps: I am using ng-i18next and it works correctly. My header looks like this:

<th field-name="website" display-name="{{'website' | i18next}}"></th>
daniboomerang commented 10 years ago

Ohhh thanks.

Since I am already using angular-translate, for translating the whole app, i´d rather try to understand why is actually doesn´t working.

Anyway...Have you tried to do something like...:

<th field-name="website" display-name="whateverfunc()"></th> where function is defined as $scope.whateverfunc = function(){return "whatever";}

Does it work for you?

Thanks again I will have a serious look to i18next if I don´t manage to understand what´s happening

joebordes commented 10 years ago

No, that did not work (as I expected). It simply showed the text whateverfunc(). The way you are putting it is simply static text.

What did work was this:

<th field-name="website" display-name="{{anytext | whateverfunc}}"></th>

with the filter:

...
.filter("whateverfunc", function() {
    return function() {
        return 'whatever';
    };
})
MoonStorm commented 10 years ago

Guys just tell me. All the docs and samples I put on that website were in vain?! Especially the localization section.

joebordes commented 10 years ago

No they are not in vain at all.

MoonStorm commented 10 years ago

In a nutshell, if you have a translate filter defined, it'll be used automatically for all the labels and table header. If that's not the filter you want, define the filter and forward the request to whatever 3rd party lib you use. Let me know if you need more help. There is no need to mess around with the display name attribute.

joebordes commented 10 years ago

Thank you for your effort. Be patient it can be daunting at times :-)