Demand
Data obtained from the background this is what God wants.
Background
Gets the tabular data from the background and populates it with Excel. Of course, it is filled with JS. The array of JS itself has the sort () function. But for a column of data. Here are two columns of data. Do you have a swollen handle? See the world of Arrayobject.sort (SortBy);
SortBy is empty by default. That is, sort by the encoding of the string.
What is the role of SortBy?
If you want to sort by other criteria, you need to provide a comparison function that compares two values and returns a number that describes the relative order of the two values. The comparison function should have two parameters A and B with the following return values:
If a is less than B, a value that is less than 0 is returned if a should appear before B in the sorted array.
If a equals B, 0 is returned.
If a is greater than B, a value greater than 0 is returned
Well, that's a good run.
Ideas
Save the result set as an array of JS objects. The object array is then sorted.
varData=[];varresult=collection of results obtained from the background for(varI=0;i<result. rowcount;i++) {Data[i]={n:result.getvalue (i, "D"), B:result.getvalue (i, "E"))}}functionCompare (PropertyName) {return function(Object1, object2) {varValue1 =Object1[propertyname]; varvalue2 =Object2[propertyname]; if(Value2 >value1) { return-1; } Else if(Value2 <value1) { return1; } Else { return0; }}}data.sort (Compare (N) ; output Excel .....
Understand
JS has a sort method, optional parameters. The parameter is a comparison function. The comparison function has two parameters, two parameters are used to compare, greater than, less than, equals. return -1,0,1 respectively
This allows the array to invoke the contrast function.
Array of JavaScript objects sorted (by account order)