javascript - AngularJS orderby with empty field -
i ordering data , working correcty except fields empty or have no value. when ordered these empty field come first. example when ordering numbers huge empty list before getting "0"-values.
i doing thise:
ng-click="predicate = 'name'; reverse=!reverse"
and
ng-repeat="name in names | orderby:predicate:reverse"
jsfiddle: http://jsfiddle.net/jzucx/1/
is there easy elegant way fix this? want empty fields come last, no matter what.
i'd write filter takes items empty name ordered array , places them @ end:
<li ng-repeat="item in (items|orderby:'name'|emptytoend:'name')">{{item.name}}</li>
code might this:
.filter("emptytoend", function () { return function (array, key) { if(!angular.isarray(array)) return; var present = array.filter(function (item) { return item[key]; }); var empty = array.filter(function (item) { return !item[key] }); return present.concat(empty); }; });
by way, fiddle doesn't contain relevant code. did use wrong link?
update 2: your fiddle filter.
Comments
Post a Comment