AngularJS orderby with empty field

前端 未结 9 1764
北海茫月
北海茫月 2020-12-05 13:19

I am ordering a my data and its working all correcty except some fields are empty or have no value. When ordered these empty field come up first. For example when ordering n

9条回答
  •  醉酒成梦
    2020-12-05 13:44

    How about this for sorting strings:

    item in (items|orderBy:['!name', 'name'])
    

    The advantage (apart from being more concise) is it sorts null & undefined with the blank strings.

    In my case I wanted the blanks & nulls & undefineds together at the top (nulls and undefineds by default sort to the bottom), so I used:

    item in (items|orderBy:['!!name', 'name'])
    

提交回复
热议问题