如果我使用不同的 api,角度表排序不起作用 [英] Angular Table sorting does not work if i use a different api
本文介绍了如果我使用不同的 api,角度表排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从
http://ng-table.com/#/loading/demo-外部数组
用代码笔打开它,而不是/data",我使用的是 api
opened it in code pen and instead of "/data" i am using an api
https://jsonplaceholder.typicode.com/posts
并添加 isArray : true
and added isArray : true
var Api = $resource("https://jsonplaceholder.typicode.com/posts", {}, {
'get': { method: 'GET', isArray: true}
});
在html中,为了简单起见,我取出了所有列并保留了id"列
in html i took out all the columns and kept "id" column for simplicity
它加载了 id 列,但搜索排序不起作用.
it loads id column but searching sorting does not work.
我做错了什么?
换过的笔在这里
http://codepen.io/raasmasood/pen/zoeMgx
推荐答案
http://codepen.io/anon/pen/rWRNjQ
你可以检查这个代码笔,现在它可以工作了.;)
you could check this codepen, now it works. ;)
getData: function(params) {
// ajax request to api
return Api.get(params.url()).$promise.then(function(data) {
params.total(100); // recal. page nav controls
return ($filter('orderBy')(data, params.orderBy()));
//return data;
});
}
以前我们错过了过滤器部分.
Previously there we missed the filter part.
return $filter('filter')($filter('orderBy')(data, params.orderBy()),params.filter());
也用于启用过滤器 :)
for enabling filter too :)
这篇关于如果我使用不同的 api,角度表排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文