简体   繁体   English

ng-grid上的升/降过滤字符串

[英]Ascending/Descending filter Strings on ng-grid

Trying out Ascending and Descending type of sorting in Angular JS with Strings 在带有字符串的Angular JS中尝试升序和降序排序类型

Here is the Plunker The select box has two options Ascending and Descending 这是“ 柱塞 ”选择框具有两个选项“ Ascending和“ Descending

when Ascending is chosen than the grid should output the values with Importance in order LMH stands for Low-Medium-High and similarly for Descending that is HML 当选择Ascending时, Ascending该输出具有重要性的值,以便LMH代表Low-Medium-High ,类似地代表HML Descending

I have already asked these questions but sorry can't get my concepts right about sorting and filtering in Angular JS 我已经问过这些问题,但是很抱歉,我对Angular JS中的排序和过滤的理解不正确

UPDATE UPDATE

I had implemented a part of it where I have sorted the contents in same order 我实现了其中的一部分,以相同的顺序对内容进行了排序

Stack Question Here i have used a drop down for selection. 堆栈问题在这里,我已使用下拉菜单进行选择。 and the same drop down has two more options of Ascending and Descending for which I am trying to find out answers. 而同一下拉菜单又有两个选项,分别是“ Ascending和“ Descending ”,我正尝试找出答案。

I don't know of any non-hackish way of using an external select such as you show in your Plunker. 我不知道使用外部select (如您在Plunker中所示)的任何非骇客的方式。

As for the sorting itself, you can create and use a custom sorting function: 至于排序本身,您可以创建和使用自定义排序功能:

var prioritySort = function(a, b){
    var priority = { L: 1, M: 2, H: 3 };
    if(priority[a] > priority[b]) return 1;
    if(priority[a] < priority[b]) return -1;
    return 0;
};

$scope.gridOptions = {
    data: 'myData',
    enableSorting: true,
    showFilter: true,
    columnDefs: [{ field: 'name', displayName: 'Name'},
    { field: 'age', displayName: 'Age' },
    { field: 'Importance', displayName: 'Importance', sortFn: prioritySort}]
};

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM