I sort collection of objects with single primary key:
mydata = _.sortBy(mydata, function (obj) {
return parseInt(obj[pk], 10);
});
But I cannot sort this numeric strings when is a composite key like ["RHID","CD_DOC_ID","SEQ"]
In Lodash v3 do:
mydata = _.sortByAll(
mydata,
[
function (obj) {
return parseInt(obj["RHID"], 10);
},
function (obj) {
return parseInt(obj["CD_DOC_IC"], 10);
},
function (obj) {
return parseInt(obj["SEQ"], 10);
}
]
);
In Lodash v4:
replace _.sortByAll with _.sortBy
If you also want to specify the sorting direction, use _.sortByOrder (v3) or _.orderBy (v4) instead.
mydata, and the expected output.