Download on GitHub
sortObjects(filters, searchTypes, source)
Sort an array of objects in JSON format by multiple properties.
sortOrder
Type:
Object
An object specifying the properties by which to sort the array of objects, the order by which to sort them, and the data type to apply to the properties.
- property1 - propertyn: property names to sort by in order, property 1 is sorted first, then property 2, etc.
- order1 - ordern: ascend or descend, default is ascend if not specified
- type1 - typen: supported type values are
- string
- number
- date (use for timestamps)
- time (of day)
source
Type:
Array of Objects
The Array of Objects to be sorted
example 1
Get an array of objects from the server and then sort and unsort it.
var source = [];
var requests = [
{ "DateStart" : "<=2/28/2014" , "DateEnd" : ">=2/1/2014" } ,
{ "DateStart" : "2/1/2014...2/28/2014" }
] ;
var query = fmxj.findRecordsURL("Events", "Events", requests) ;
fmxj.postQueryFMS(query, writeResults);
function writeResults(js){
source=js;
var display = source.splice(0,500);
document.getElementById("example1").innerHTML=JSON.stringify(display, null, 4);
};
Apply Sort
var sort = {
"property1" : "DateStart" ,
"sort1" : "descend" ,
"type1" : "date",
"property2" : "Resource" ,
"order2" : "ascend",
"type2" : "string"
} ;
fmxj.sortObjects(sort, source) ;
var display = filter.splice(0,500);
document.getElementById("example1").innerHTML=JSON.stringify(display, null, 4);