angularjs - Creating a table header(th) and body(td) from json in angular app -
i have angular app trying create table json. json follows:
[ { "campus_id": "321", "name": "0" }, { "campus_id": "231", "name": "1" }, { "campus_id": "123", "name": "2" } ]
generally create table in html follows:
<table class="table table-striped"> <tr> <th> campus id </th> <th> name </th> </tr> <tr ng-repeat="item in items"> <td > {{item.campus_id}} </td> <td > {{item.name}} </td> </tr> </table>
how create headers json instead of defining them ourselves?
i add column headers within json result so
columndefs: [ {field: 'campus_id', displayname: 'campus id'}, {field: 'name', displayname: 'name'}], data: [ { "campus_id": "57911000", "name": "0" }, { "campus_id": "57911001", "name": "highland park high school" }, { "campus_id": "57911007", "name": "p s s learning center school" } ]
otherwise use key, value pairing ng-repeat="(key,value) in items" filter return 1 row , use {{key}}
Comments
Post a Comment