SeedCode Logo


fmxj.js
a JavaScript approach to FileMaker Custom Web Publishing™

gh LogoDownload 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.
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);