Isaac
asked on
sort Multi-dimensional array
I am trying to sort a multi-dimensional array. In my code, I capture data (item 'ID' and 'Priority' value) from my SharePoint list and dump it into an array as objects. For some odd reason, it does not get inserted in the order I expected so I am trying to sort the array by the 'ID'.
Here's my code that created the array of objects.
Here's an image of what it looks like when I capture what's going on in the developer tool.
I also created a mock-up in jsfiddle.
https://jsfiddle.net/isogunro/fkspbzh9/4/
Here's my code that created the array of objects.
/*Array will contain two values, item id and new priority value. Global so it can be used in multiple functions.*/
var items = [];
var itemsID = [];
var projItemArray = new Array();
var i = 0;
/*-------------------------------------------------------------------------------------------------------*/
//Success on data retrieval from 'retrieveListItems()'. Transforms HTML table to datatable and creates
//range functionality.
/*-------------------------------------------------------------------------------------------------------*/
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
//Will be used to build object array of ID and priorityNumber
//var projItemArray = new Array();
//1st call to retrieve the level. 2nd call below while loop
var levels = determineGroup();
// alert("onQuery: "+levels);
var i = 0;
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var itemUid = oListItem.get_item('ID');
var colVal;
var valSelect = " ";
if (oListItem.get_item('Approval') != null) {
valSelect = "selected";
colVal = oListItem.get_item('Approval');
} else {
colVal = "N/A";
}
projItem = {};
projItem.ID = oListItem.get_item('ID');
projItem.priorityNumber = oListItem.get_item(levels);
htmlTbl += "<tr class='NRM_pj_align'><td>" + itemUid + "</td>" +
"<td>" + checkForNull(oListItem.get_item('Title')) + "</td>" +
"<td>" + checkForNull(oListItem.get_item('Prioritization_x0020_Total')) + "</td>" +
"<td data-order=" + oListItem.get_item('Priority') + "> " +
"<input type='text' size='1' disabled name = 'rowID-" + oListItem.get_item('ID') + "' id='facilityRowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('Priority') + " value=" + checkForNull(oListItem.get_item('Priority')) + ">" +
"</td>" +
"<td data-order=" + oListItem.get_item('Priority_level2') + "> " +
"<input type='text' size='2' disabled name = 'rowID-" + oListItem.get_item('ID') + "' id='STATERowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('Priority_level2') + " value=" + checkForNull(oListItem.get_item('Priority_level2')) + ">" +
"</td>" +
"<td data-order=" + oListItem.get_item('Priority_level3') + "> " +
"<input type='text' size='2' disabled name = 'rowID-" + oListItem.get_item('ID') + "' id='nationalRowID-" + oListItem.get_item('ID') + "' data-curVal=" + oListItem.get_item('Priority_level3') + " value=" + checkForNull(oListItem.get_item('Priority_level3')) + ">" +
"</td>" +
"<td>" + checkForNull(oListItem.get_item('Project_x0020_Number')) + "</td>" +
"<td>" + checkForNull(oListItem.get_item('STATE')) + "</td>" +
"<td>" + checkForNull(oListItem.get_item('Station')) + "</td>" +
"<td>" + checkForNull(oListItem.get_item('Total_x0020_Project_x0020_Cost')) + "</td>" +
"<td>" + constructionDesign(oListItem.get_item('Design_x0020_Obligation_x0020_Da'), oListItem.get_item('Services'), "Services") + "</td>" +
"<td>" + constructionDesign(oListItem.get_item('Construction_x0020_Obligation_x0'), oListItem.get_item('Construction_x0020_Cost'), "Budget") + "</td>" +
"<td><select id='Approval' class='oApproval" + itemUid + "' onchange='update(\"NF Operating Plan\"," + itemUid + ",\"Approval\")'><option value='' selected></option><option value='NF Operating Plan'" + valSelect + ">NF Operating Plan</option></select></td></tr>";
projItemArray[i] = projItem;
i++;
}
}
Here's an image of what it looks like when I capture what's going on in the developer tool.
I also created a mock-up in jsfiddle.
https://jsfiddle.net/isogunro/fkspbzh9/4/
ASKER
As you can see above, it modified my ID's
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did not work either. see fiddle
https://jsfiddle.net/isogunro/fkspbzh9/5/
https://jsfiddle.net/isogunro/fkspbzh9/5/
ASKER
Never mind. It did work. sorry
Open in new window