2016-03-01 33 views
1

我需要做一个多列排序。它必须是“高(红色 - 不例子,因为它是一个零计数)”,“中(橙色)”,“低(黄色)” ..像下面的图片..独特的多列排序角js

Correct Sorting

然而,当我使用角JS排序,我得到以下..

incorrect Sorting

NG重复

<tr ng-repeat="pat in vm.patients.slice(((vm.tableParams.currentPage-1)*vm.tableParams.pageSize), ((vm.tableParams.currentPage)*vm.tableParams.pageSize)) | orderBy:vm.tableParams.sortType:vm.tableParams.sortReverse track by $index" ng-click="vm.showPatientDetail(pat.PatientNum)"> 

当单击列标题。

<th ng-click="vm.setSortType('')"> 
        <span> 
         Other Alerts &nbsp; 
         <i class="fa fa-sort"></i> 
        </span> 
       </th> 

的setSortType功能... vm.patients的

vm.setSortType = function (sortType) { 
     vm.tableParams.sortReverse = !vm.tableParams.sortReverse; 

     if (sortType == '') { 
      vm.tableParams.sortType = "['AlertHighCount', 'AlertMediumCount', 'AlertLowCount']"; 
      return; 
     } 

     vm.tableParams.sortType = sortType; 
    } 

样本数据。该AlertHighCount将是第一个,AlertMediumCOunt,然后AlertLowCount

{ 
    "PatientNum": 56, 
    "LastName": "Patient", 
    "FirstName": "Demo", 
    "PatientName": "Patient, Demo", 
    "PatientBirthDate": "1942-12-12T00:00:00", 
    "PrescribePhys": 0, 
    "PhysicianFirstName": null, 
    "PhysicianLastName": null, 
    "TreatmentCount": 0, 
    "AlertHighCount": 1, 
    "AlertMediumCount": 2, 
    "AlertLowCount": 0, 
    "AlertLevel": 0, 
    "DeviceType": 1, 
    "PMSPatient": 0 
    }, 
    { 
    "PatientNum": 727, 
    "LastName": "cat", 
    "FirstName": "cat", 
    "PatientName": "cat, cat", 
    "PatientBirthDate": null, 
    "PrescribePhys": 0, 
    "PhysicianFirstName": null, 
    "PhysicianLastName": null, 
    "TreatmentCount": 0, 
    "AlertHighCount": 0, 
    "AlertMediumCount": 2, 
    "AlertLowCount": 1, 
    "AlertLevel": 0, 
    "DeviceType": 1, 
    "PMSPatient": 0 
    }, 
    { 
    "PatientNum": 1036, 
    "LastName": "Cat", 
    "FirstName": "Cat", 
    "PatientName": "Cat, Cat", 
    "PatientBirthDate": null, 
    "PrescribePhys": 0, 
    "PhysicianFirstName": null, 
    "PhysicianLastName": null, 
    "TreatmentCount": 0, 
    "AlertHighCount": 0, 
    "AlertMediumCount": 1, 
    "AlertLowCount": 5, 
    "AlertLevel": 0, 
    "DeviceType": 1, 
    "PMSPatient": 0 
    }, 
    { 
    "PatientNum": 1040, 
    "LastName": "Cat", 
    "FirstName": "Cat", 
    "PatientName": "Cat, Cat", 
    "PatientBirthDate": null, 
    "PrescribePhys": 0, 
    "PhysicianFirstName": null, 
    "PhysicianLastName": null, 
    "TreatmentCount": 0, 
    "AlertHighCount": 0, 
    "AlertMediumCount": 1, 
    "AlertLowCount": 3, 
    "AlertLevel": 0, 
    "DeviceType": 1, 
    "PMSPatient": 0 
    } 
+0

不清楚什么样的数据实际上是被排序或你打算如何管理这些。 [plunker](http://plnkr.co/edit/?p=catalogue)中的简化演示将有助于 – charlietfl

+0

每个对象中有3列称为'AlertHighCount','AlertMediumCount','AlertLowCount'。默认情况下,我需要先按高,然后中,然后再按低排序。在上面的例子中,High缺失是因为当计数为零时隐藏它。不幸的是,它是我必须处理的唯一示例数据。如果您查看第一个图像,则会看到它先排列中等,然后是低。第二个图像是排序我上面的代码正在返回.. – dave

+0

不难从浏览器开发工具网络复制数据示例或将字符串化对象记录到控制台。我们无法操纵图像。您可能需要在'vm.setSortType'中定义一个对象 – charlietfl

回答

2

你想要的排序依据的参数是一个数组不是字符串

尝试

vm.tableParams.sortType = ['AlertHighCount', 'AlertMediumCount', 'AlertLowCount'];