I have a JSON object that has peoples names and a true and false item that asks if they are a contact. This is pulled from a Government API into a Vue application using a commercial Grid component from Syncfusion. I'm pulling the api with axios. Everything works fine except my sorting of object using code inside the Grid. I starting to think I need to make a deep copy then sort. This is the object as it is called from the api, it may not be perfectly formatted since I did a cut and paste
"principal_investigators": [
{
"profile_id": 1873970,
"first_name": "K",
"middle_name": "T.",
"last_name": "B",
"is_contact_pi": false,
"full_name": "K T. B",
"title": null
},
{
"profile_id": 1866589,
"first_name": "F",
"middle_name": "R",
"last_name": "XL",
"is_contact_pi": true,
"full_name": "F R L",
"title": null
}
{
"profile_id": 1863489,
"first_name": "F",
"middle_name": "R",
"last_name": "ZQ",
"is_contact_pi": false,
"full_name": "F R Z",
"title": null
}
}]
It seems that inside the component in a browser watch all of the keys are in alpha order so is_contact_pi is in position third in the list. I have tried deep cloning it 3 different ways. It always stays in the original sort order and I have tried 2 different sort code.
principalInvestigators: function(field, data, column){
if(data["principal_investigators"] !=""){
let aux = data["principal_investigators"]
// let clone = (items) => items.map(item => aux.isArray(item) ? clone(item) : item);
// let clone = JSON.parse(JSON.stringify(aux));
let clone = [...aux];
console.log(aux)
console.log(clone)
console.log("first clone")
// sort based upon is_contact_pi is_contact_pi
clone.sort(function (x, y) {
//return (y === x)? 0 : x[2]? 1 : -1;
return (y[2] === x[2])? 0 : x[2]? 1 : -1;
});
// let x = aux
console.log(aux)
console.log(clone)
console.log("second clone")
let principal =""
for (var i = 0; i < clone.length; i++) {
principal += clone[i]["full_name"] + '\n'
}
return principal
} else {
return ""
}
},
This maybe a question for Syncfusion and I may send it to them also tonight. But does anyone think they have a solution or even a possible idea? Build my principle string from 2 different loops? One that is build from false and one that is build from true then join them? I need to end up with the is contact first in the principal string with the rest following