Dynamically defined data-title with ng-table
Asked Answered
F

1

7

I am working towards using ng-table to display reports in a tabular manner. However I have run into a problem using the data-title attribute and dynamically assigning the heading.

In the following example I am attempting to set the data-title attribute as follows.

<td ng-repeat="field in user" data-title="'{{ fields[$index] }}'">
  {{ field }}
</td>

$scope.fields = ["Names", "Ages"]; is defined within the controller. When inspecting the element, the data-title attribute is properly set however the headings are not properly processed resulting in the heading {{ fields[$index] }}.

Here is a live example: http://plnkr.co/edit/gBS6FGINayYufPGqCMxb?p=preview

Fivepenny answered 11/6, 2014 at 16:0 Comment(0)
F
0

1stofall, you have unnessesary '' in {{fields[$index]}}.

2nd - yes, it can be dynamic: fields array item mast have title attrib.

<table ng-table-dynamic="tableParams with columns" show-filter="false" class="table table-bordered table-striped">
    <tbody>
      <tr ng-repeat="user in $data">
        <td ng-repeat="col in $columns">{{user[col.field]}}</td>
      </tr>
    </tbody>
  </table>

i've edited for you old example that was on ngTable's old site.

you shoud use this example - Updated Example 20: Dynamic columns

Flirtatious answered 12/9, 2015 at 0:17 Comment(3)
The example does not work and your code does not work.Fivepenny
@user3730788 - hmm... updated broken source for ng-table.min.jsFlirtatious
Thanks a lot for this answer, working like a charm :)Impenitent

© 2022 - 2024 — McMap. All rights reserved.