1

I need to do a multiple column sort. It needs to be "High (Red - Not in example because it's a zero count)", "Medium (Orange)", "Low (Yellow)".. like the image below..

Correct Sorting

However, when I use Angular JS Sorting, I get the following..

incorrect Sorting

ng-repeat

<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)">

When the column header is clicked.

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

The setSortType function...

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

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

        vm.tableParams.sortType = sortType; 
    }

sample data of vm.patients. The AlertHighCount would be first, AlertMediumCOunt, then 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
  }
6
  • Not clear what data is actually being sorted or how you intend to manage toggling these. A simplified demo in plunker would help Commented Mar 1, 2016 at 18:27
  • There are 3 columns in each object called 'AlertHighCount', 'AlertMediumCount', 'AlertLowCount'. By default, I need it to sort first by High, then Medium, then Low. In the example above, High is missing because I hide it when count is zero..unfortunately it's the only sample data I have to work with.. If you look at the first image, you'll see it sorts Medium first, then Low. The second image is the sorting my code above is returning.. Commented Mar 1, 2016 at 18:34
  • not hard to copy data sample from browser dev tool network or log a stringified object to console. We can't manipulate an image. You probably need to define an object in vm.setSortType Commented Mar 1, 2016 at 18:36
  • In the setSortType function, I set sortType = "['AlertHighCount', 'AlertMediumCount', 'AlertLowCount']"; And then apply it to the OrderType Commented Mar 1, 2016 at 18:43
  • Should be actual array though, not string. try just removing outer quotes Commented Mar 1, 2016 at 18:45

1 Answer 1

2

You are wanting the orderby parameter to be an array not a string

Try

vm.tableParams.sortType = ['AlertHighCount', 'AlertMediumCount', 'AlertLowCount'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.