question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mdt-column and mdt-cell not able to handle complex ng-repeat

See original GitHub issue

I found two issues with ng-repeat in mdt-column and mdt-cell. They seem very related, so I put them into one ticket. Both are a bit related to https://github.com/iamisti/mdDataTable/issues/68, but a different case though, therefore opening a new ticket. I took the Demo table and wanted to replace the static column names with dynamic ones.

(1) mdt-column and ng-repeat

I added this to the controller:

$scope.columns = [];
$scope.columns["nutritions"] = [
          {"title":"Dessert (100g serving)", "field":"name", "sortable":true}, 
          {"title":"Calories", "field":"calories", "sortable":true},
          {"title":"Fat (g)", "field":"fat", "sortable":true},
          {"title":"Carbs (g)", "field":"carbs", "sortable":true},
          {"title":"Protein (g)", "field":"protein", "sortable":true},
          {"title":"Sodium (mg)", "field":"sodium", "sortable":true},
          {"title":"Calcium (%)", "field":"calcium", "sortable":true},
          {"title":"Iron (%)", "field":"iron", "sortable":true}       
] 

and with this in html code, it works:

<mdt-column align-rule="left" ng-repeat="column in columns['nutritions']">{{column.title}}</mdt-column>

but as soon as I add another reference field into the mdt-column tag body, it fails, i.e.:

<mdt-column align-rule="left" ng-repeat="column in columns['nutritions']">{{column.title}} / {{column.field}}</mdt-column>

The header is not shown at all anymore.

CodePen for this example: http://codepen.io/mathiasconradt/pen/ZQNrvM

(2) mdt-cell and ng-repeat

The other issue is when I also try to handle the mdt-cell fields dynamically via ng-repeat.

Based on above code base:

<mdt-cell ng-repeat="column in columns['nutritions']">{{nutrition[column.field]}}</mdt-cell>  

The data values are not shown at all.

CodePen for this example: http://codepen.io/mathiasconradt/pen/OMYQdj

Both ng-repeat code samples work fine when used with just a <div>-tag, but not with mdt-cell or mdt-column.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Gaglia88commented, Jul 4, 2016

Hi, I solved the problem in my case… In the md-data-table.js on line 875 there is this assignment: var cellValue = $parse(clone.html().replace('{{', '').replace('}}', ''))($scope.$parent);

How you can see it evaluates the function that you put in the mdt-cell using the scope of it’s parent (mdt-row), thus it uses the scope of the row and it cannot find the variable ‘column’…

So, If you modify the code in this way var cellValue = $parse(clone.html().replace('{{', '').replace('}}', ''))($scope); it uses the right scope and it able to read the ‘column’ variable.

0reactions
yghelmutcommented, May 10, 2017

Found a quick fix:

var content = clone.html() ? clone.html() : clone.text(); var cellValue = $interpolate(clone.html())($scope.$parent);

Read more comments on GitHub >

github_iconTop Results From Across the Web

ng-repeat cannot handle array with non-continuous number ...
Angular tries to determine if the object is array like object or not. Once it determines, it sets its trackBy property based on...
Read more >
md-data-table - npm
In its simplest form, a data table contains a top row of column names, and rows for data. A selected table row. Table...
Read more >
ngRepeat - AngularJS: API
The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found