How to set dynamic data-title in ngtable (angular plugin)
Asked Answered
C

3

6

I want have a multi language view with an ngTable. For do that, i set in my controller a $scope.translate (a valid json) who contains my traductions. In my view i want set my data-title like {{translate.code}} etc...

my view :

<table ng-table="tableParams" class="table ng-table-responsive">
        <tr ng-repeat="product in $data">
            <td data-title="'{{translate.code}}'" > <!-- display : {{translate.code}} -->
                {{product.code}}
            </td>
            <td data-title="['translate.reference']" > <!-- display : empty -->
                {{product.reference}}
            </td>
            <td data-title="'Label'" >
                {{product.label}}
            </td>
            <td data-title="'Size'" ng-show="manageSizeColor == true">
                {{product.size}}
            </td>
            <td data-title="'Quantity'" >
                <ac-quantity minquantity="1" cquantity="product.quantity"></ac-quantity>
            </td>
            <td data-title="'Price'">
                <b>{{product.price + currency}}</b>
            </td>
        </tr>
    </table>
Catenate answered 24/6, 2014 at 7:45 Comment(0)
C
9

I' ve finally found how do this, with this example : https://github.com/esvit/ng-table/issues/53

<td data-title="translate['reference']" >
   {{product.reference}}
</td>

where translate is the scope variable and ['reference'] is the property

Catenate answered 24/6, 2014 at 8:4 Comment(0)
O
13

If you're using angularjs ~1.2 with angular-translate ~2.6.1, translation on data-title works like this:

<td data-title="'MY_TRANSLATION_ID' | translate" >
{{product.reference}}
</td>
Orelle answered 10/3, 2015 at 8:54 Comment(0)
C
9

I' ve finally found how do this, with this example : https://github.com/esvit/ng-table/issues/53

<td data-title="translate['reference']" >
   {{product.reference}}
</td>

where translate is the scope variable and ['reference'] is the property

Catenate answered 24/6, 2014 at 8:4 Comment(0)
R
0

you can also do this :

<td data-title="getColumnName('your.translate.code')">{{ resultat.number }}</td>

with in your controller :

$scope.getColumnName = function(column) {
    return $translate.instant(column);
}
Radiotelegraph answered 26/1, 2016 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.