SQL Server数据透视表返回视图(AngularJS)



将数据从sql server返回给视图,这对我来说是一个问题。我的问题是如何将列标题从数据库返回到angular应用程序视图中的表。标题是动态的,这意味着当用户向数据库中的person表中添加一个新的人时,数据透视表将获得一个包含新人名的新列。

我正在使用c# ASP。. NET WebAPI 2 &SQL Server 2012用于服务器端,AngularJS用于客户端。

REST服务与SQL Server中的存储过程一起工作。

例如,正常的表是:

firstname | lastname | age |
John      |    Doe   |  20 |
Peter     |    Keller|  19 |
Chris     |    Brown |  30 |
Christy   |    Buzzy |  20 |
Phil      |    Brown |  34 |
.....

和PIVOT表:

age | Doe | Keller | Brown | Buzzy ....
34  |  0  |    1   |   1   |   0
...
30  |  4  |    0   |   1   |   0
...
20  |  1  |    0   |   0   |   0

表表示例如姓"Doe"的人中有4人30岁,以此类推。

<table class="table table-striped no-margin">
<thead>
     <tr>
          <th>Age</th>
          <th ng-repeat="l in lastnames">{{l.lastname}}</th>
     </tr>
</thead>
<tbody>
      <tr ng-repeat="a in age">
         <td>{{a.age}}</td>
         <td ng-repeat="c in count track by $index">{{c.count}}</td>
      </tr>
</tbody>
</table>

希望这是你想要的。在标题中使用ng-repeat

最新更新