Sort By Field REST API Result In SharePoint
Function for JSON Object sorting
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
Sort REST API JSON Result in SharePoint as below
//function of rest api success call
function OnSuccessGetItem(data)
{
var result=data.d.results;
//sorting result by title
result.sort(dynamicSort("Title"));
}
Comments
Post a Comment