sorts datastore
Method sort can be used with different count of parameters.
The most common use case of sort method is using first parameter as name of the property:
data.sort("#Package#","asc","string");
Property name should be included into sharps.
First parameter of sort method may be function, which recives 2 DataStore objects. In such case you can access to all properties of comparing objects:
data.sort(by_func,"des"); //3rd parameter will be ignored function by_func(a,b){ //a, b - DataStore objects return a.Version > b.Version ? 1 : -1; }
Possible return values of this fucntion are 0,1,-1. '1' means first object is greater than second object, '-1' means first object is less than second object, '0' means 2 objects are equal
Also you can use hash of sorting settings as first parameter of sort method:
data.sort({ as:"string", dir:"des", by:"#Package#" }); //2nd and 3rd parameters will be ignored
Possible value for second parameter of sort method is string which represents sorting direction:
Third parameter of sort method may be string which represeints type of data:
data.sort("#Version#","des","int");
Also 3rd parameter may be function, which recives 2 parameters - content of corresponding property. In such case you will not have access to all properties of comparing objects:
data.sort("#Maintainer#","des",as_func); function as_func(Maintainer1,Maintainer2){ //Maintainer1,Maintainer2 - content of Maintainer property of 2 object from DataStore return Maintainer1.length>Maintainer2.length ? 1:-1; }
As for first parameter, this function should return 1,-1 or 0.