【问题标题】:SQL Server PIVOT table returns to view (AngularJS)SQL Server PIVOT 表返回查看(AngularJS)
【发布时间】:2015-12-05 14:22:01
【问题描述】:

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

我在服务器端使用 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

表格表示例如 4 个姓“Doe”的人 30 岁,以此类推。

【问题讨论】:

  • @nicolaskruchten 你能告诉我如何将 PivotTable.js 用于 Angular 吗?我已经下载了 zip 文件,但只有 coffeescript 文件。

标签: javascript c# sql-server angularjs asp.net-web-api


【解决方案1】:
<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 作为标题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多