Reputation: 487
I'm trying to get the table header for each column from JavaScript, however calling tableTest
only returns data of each row of column, is there a way to return the header like 'name' and 'description'. Maybe sort of tableTest.data-title
<table ng-table="tableTest">
<tbody>
<tr ng-repeat="sample in $data">
<td data-title="'Name'" sortable="'name'">
{{sample.name}}
</td>
<td data-title="'Description'" sortable="'description'">
{{sample.description}}
</td>
</tr>
</tbody>
</table>
Thanks
Upvotes: 1
Views: 1785
Reputation: 31901
How about a doing it through javaScript
?
See this Plunker code
HTML
<table ng-table="tableParams" id="myTable">
<tbody>
<tr ng-repeat="sample in $data">
<td data-title="'Name'" sortable="'name'">
{{sample.title}}
</td>
<td data-title="'Description'" sortable="'description'">
{{sample.description}}
</td>
</tr>
</tbody>
</table>
<script>
//gets table
var oTable = document.getElementById('myTable');
//gets rows of table
var rowLength = oTable.rows.length;
//loops through rows
for (i = 0; i < rowLength; i++) {
//gets cells of current row
var oCells = oTable.rows.item(i).cells;
//gets amount of cells of current row
var cellLength = oCells.length;
//loops through each cell in current row
for (var j = 0; j < cellLength; j++) {
// get your cell info here
var cellTitle = oCells.item(j).getAttribute("data-title");
document.write("Header for Row#" + j + " : " + cellTitle + "<br>");
}
}
</script>
Output
Header for Row#0 : 'Name'
Header for Row#1 : 'Description'
Upvotes: 4