我正在尝试创建一个可以排序和过滤的表格, 我复制了ngTable示例中的代码,但它无法正常工作。我无法过滤,我无法排序。
我搜索了一个解决方案,但我看到的所有答案都是旧版本的,他们改变了现在的工作方式。
这是我的代码:
HTML:
<div ng-app="myApp">
<div ng-controller="demoController as demo">
<h2 class="page-header">Loading data - External array</h2>
<table ng-table="demo.tableParams" class="table table-condensed table-bordered table-striped">
<tr ng-repeat="row in $data">
<td data-title="'MyProperty'" sortable="'MyProperty'" filter="{MyProperty: 'number'}">{{row.MyProperty}}</td>
</tr>
</table>
</div>
</div>
JS:
var app = angular.module("myApp", ["ngTable", "ngResource"]);
(function () {
app.controller("demoController", demoController);
demoController.$inject = ["NgTableParams", "$resource"];
function demoController(NgTableParams, $resource) {
var Api = $resource('Home/user');
this.tableParams = new NgTableParams({
filter: { MyProperty: 1 },
sorting: { MyProperty: "123" }
}, {
getData: function (params) {
// ajax request to api
return Api.query(params.url()).$promise.then(function (data) {
params.total(data.length); // recal. page nav controls
return data;
});
}
});
}
})();
C#:
public JsonResult user()
{
List<Models.Bae> hw = new List<Models.Bae>();
for (int i = 0; i < 500; i++)
{
Models.Bae ba = new Models.Bae(i);
hw.Add(ba);
}
return Json(hw, JsonRequestBehavior.AllowGet);
}