3 r*_*les 10 datatables angularjs angular-datatables
您好我正在使用angularjs创建一个应用程序,并使用数据表js创建ASP.NET MVC.
我一直在使用的数据表与帮助的角度JS实现表显示数据此文章.
但我想在html中使用相同的功能与静态的列名绑定数据,如:
在文章中,作者使用以下方法完成了
<table id="entry-grid" datatable="" dt-options="dtOptions"
dt-columns="dtColumns" class="table table-hover">
</table>
Run Code Online (Sandbox Code Playgroud)
但是我希望按照我的数据使用ng-repeat使用相同的功能,这样做:
<table id="tblusers" class="table table-bordered table-striped table-condensed datatable">
<thead>
<tr>
<th width="2%"></th>
<th>User Name</th>
<th>Email</th>
<th>LoginID</th>
<th>Location Name</th>
<th>Role</th>
<th width="7%" class="center-text">Active</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in Users">
<td><a href="#" ng-click="DeleteUser(user)"><span class="icon-trash"></span></a></td>
<td><a class="ahyperlink" href="#" ng-click="EditUser(user)">{{user.UserFirstName}} {{user.UserLastName}}</a></td>
<td>{{user.UserEmail}}</td>
<td>{{user.LoginID}}</td>
<td>{{user.LocationName}}</td>
<td>{{user.RoleName}}</td>
<td class="center-text" ng-if="user.IsActive == true"><span class="icon-check2"></span></td>
<td class="center-text" ng-if="user.IsActive == false"><span class="icon-close"></span></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我还想在按钮中单击添加新记录使用相同的功能在表格中添加新列.
可能吗?
如果是的话怎么可能会很好,如果有人在jsfiddle或任何编辑器中向我展示,那么事先谢谢.
请下载在Visual Studio Editor中创建的源代码以进行演示
您可以使用davidkonrad建议注释中的链接,如下面的结构:
HTML:
<table id="entry-grid" datatable="ng" class="table table-hover">
<thead>
<tr>
<th>
CustomerId
</th>
<th>Company Name </th>
<th>Contact Name</th>
<th>
Phone
</th>
<th>
City
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in Customers">
<td>{{c.CustomerID}}</td>
<td>{{c.CompanyName}}</td>
<td>{{c.ContactName}}</td>
<td>{{c.Phone}}</td>\
<td>{{c.City}}</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
以角度创建控制器,如下所示:
var app = angular.module('MyApp1', ['datatables']);
app.controller('homeCtrl', ['$scope', 'HomeService',
function ($scope, homeService) {
$scope.GetCustomers = function () {
homeService.GetCustomers()
.then(
function (response) {
debugger;
$scope.Customers = response.data;
});
}
$scope.GetCustomers();
}])
Run Code Online (Sandbox Code Playgroud)
服务:
app.service('HomeService', ["$http", "$q", function ($http, $q) {
this.GetCustomers = function () {
debugger;
var request = $http({
method: "Get",
url: "/home/getdata"
});
return request;
}
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7353 次 |
| 最近记录: |