Comments (11)
Hi
It is a supported use case adding columns at runtime, with help of ng-repeat
. But the code you pasted here don't make use of ng-repeat
, it's plain DOM access, and this is not supported.
You can solve this requirement with plain Angular:
<thead>
<tr>
<th ng-repeat="column in columnNames">{{column}}</th>
</tr>
</thead>
from angular-responsive-tables.
Could it be a typo in the template where you have: <th ng-repeat="columnin columnNames">{{column}}</th>
?
Other than that, I don't see why it wouldn't work. Can you please provide a plunker?
from angular-responsive-tables.
I don't think that will help. ng-repeat
already has a higher priority.
My best guess is that when the ng-repeat
runs producing this:
<th>{{column}}</th>
<th>{{column}}</th>
it fails somewhere to retrieve the correct column name during interpolation. Each DOM element should have a separate $scope
with a column
property by that point. This component takes this text to produce a data-title
attribute on each tbody td
.
from angular-responsive-tables.
Ok, I tried using plain Angular, but it didn't work either =/... Here's the code:
The directive:
.directive('myTableDirective', ['URL', function(URL){
return {
restrict: 'E',
templateUrl: URL.tableComponent,
scope: {
itemList: '=',
columnNames: '=',
attributeNames: '='
},
controller: 'MyTableController'
};
}]);
The template:
<table wt-responsive-table>
<thead>
<tr>
<th ng-repeat="columnin columnNames">{{column}}</th>
</tr>
</thead>
<tbody ng-show="itemList && itemList.length > 0">
<tr ng-repeat="itemList in itemList" ng-init="item.checked = false" ng-click="item.checked = !item.checked">
<td ng-repeat="attribute in attributeNames">{{item[attribute]}}</td>
</tr>
</tbody>
</table>
The element:
<my-table-directive
item-list="itemList"
column-names="['First Name','Last Name']"
attribute-names="['firstname','lastname']">
</my-table-directive>
The controller sets
itemList = [
{
firstname: 'test11',
lastname: 'test12'
},
{
firstname: 'test21',
lastname: 'test22'
}
];
The table shows the values correctly at first. Everything ok. The problem is when I size down the screen and the table enters responsive mode. When the table's layout changes, the column names disappear.
from angular-responsive-tables.
I made this one without using directives, but I got the same result: https://embed.plnkr.co/QH65eaSF15yeZkT48XrA/
from angular-responsive-tables.
It may be some scoping issue. If there's some static text around where there's that {{column}}
, that static text shows up in responsive mode.
I see nothing that should prevent you from using this solution. One thing you may want to try is creating a directive with a higher precedence than this component (priority > 0) to render each <th>
in place before this component has a chance to run.
from angular-responsive-tables.
I tried changing the priority of my directive. I never needed to set the priority of a directive before, so I set 'priority' to 1. It didn't work =/
Should I create another directive that will contain my current one?
from angular-responsive-tables.
I see. Indeed data-title
is not being set. I'll try to figure something out. Maybe generating the whole table on runtime.
Thanks!
from angular-responsive-tables.
I worked around it by adding data-title="{{columnNames[$index]}}"
to the <td></td>
from angular-responsive-tables.
There's an incompability with the ng-repeat
inside a <th>
. Usually, the headers will be expanded & linked after this directive has opportunity to run. Ideally, every time the ng-repeat
runs, we should reapply the directive binding code.
To work around this limitation, either use static <th>
's or use the data-title
attribute as explained above. Interpolation and filters should work just fine.
There's a quick and dirty check that could be applied but still wouldn't solve most dynamic setups. So I'll leave this open for anyone interested in tackling this as an enhancement.
from angular-responsive-tables.
Fix released in v0.2.0. plunker updated: https://embed.plnkr.co/pSoSnRzf0gNMVsH5nFs4/
from angular-responsive-tables.
Related Issues (20)
- Title of first header is repeated for all columns if headers are being used on first column
- Long table names overlap in small devices mode HOT 3
- Date picker popup not showing up correctly when screen size is small (on mobile) HOT 17
- Headercolumn translation within data-title HOT 13
- "Error: th is null" when some TD's are mutually exclusive HOT 12
- colspan/rowspan in responsive mode HOT 7
- V0.3.0 Error "Controller 'wtResponsiveTable', required by directive 'td', can't be found!" HOT 2
- Use of getAttributeNode() is deprecated
- TypeError: tableCtrl.contains is not a function
- wt-responsive-table directive not working if under a container with ng-if HOT 4
- Allow th with ng-repeat over data from promise/remote HOT 4
- responsive-omit-title doesn't seem to work in v0.4.4 HOT 2
- bower.json auto includes css HOT 3
- Support Angular 2+ HOT 2
- npm registry Label: question HOT 1
- Add to npm registry HOT 2
- Need examples With Huge Export Options For Reference HOT 1
- Feature Request
- Support td[colspan]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-responsive-tables.