ng-table icon indicating copy to clipboard operation
ng-table copied to clipboard

Support dynamic columns

Open cyrusdavid opened this issue 13 years ago • 8 comments

This might already be supported that I just don't know how to do it right.

$scope.users = [
  {name: 'teemo', age: 15},
  {name: 'volibear', age: 16},
  {name: 'lee sin', age: 17},
  {name: 'lissandra', age: 18},
  {name: 'caitlyn', age: 19}
];

$scope.fields = [
  {key: 'name', title: 'Champion Name'},
  {key: 'age', title: 'Champion Age'}
];
<table ng-table class="table">
<tr ng-repeat="user in users">
    <td data-title="field.title" ng-repeat="field in fields">{{user[field.key]}}</td>
</tr>
</table>

The only thing I'm having problems with is it's not displaying the title :smirk:

Demo

cyrusdavid avatar Nov 03 '13 09:11 cyrusdavid

+1

simukka avatar Nov 08 '13 18:11 simukka

Have you tried:

<td data-title="{{field.title}}" ng-repeat="field in fields">{{user[field.key]}}</td>

I don't know if it works but if is an attribute that's how you would bind it to a string.

bferreira avatar Nov 14 '13 12:11 bferreira

I have, but because $parse is used on the data-title, it's not able to expose the binding in arrays.

This is the error when trying to bind the attrbibute to a string: Error: [$parse:syntax] Syntax Error: Token 'segment' is unexpected, expecting [:] at column 3 of the expression [{{segment}}] starting at [segment}}].

simukka avatar Nov 14 '13 17:11 simukka

please, look this example https://github.com/esvit/ng-table/blob/master/examples/demo20.html

esvit avatar Nov 16 '13 20:11 esvit

imo, this qualifies as a hack. My one major issue is that this does not meet the HTML table spec. I should be able to add dynamic columns in the <thead>.

simukka avatar Nov 18 '13 22:11 simukka

I agree seems backwards to me rather than passing the title from the same place which is what will happen with most API's

nwhite89 avatar Jan 20 '14 18:01 nwhite89

+1. I have the same problem, and it also applies to the pagination since colspan is not set correctly. It doesn't feel right to have to copy the default header & footer templates into my own code just because I've got a dynamic column list coming back from the server. I've already bound the dynamic "columns" variable to the ng-table directive.

derekrprice avatar May 20 '14 18:05 derekrprice

+1. I have checke the example https://github.com/esvit/ng-table/blob/master/examples/demo20.html . The td in tfoot is keep use colspan="0". That will broke the table's layout.

vitrum avatar May 28 '14 06:05 vitrum