return ( (b < a) ? false : ((b > a) ? true : 0) );
}
- function checkSorting( array1, array2, sortList ) {
- var col, fn, ret;
- for ( var i = 0, len = sortList.length; i < len; i++ ) {
- col = sortList[i][0];
- fn = ( sortList[i][1] ) ? sortTextDesc : sortText;
- ret = fn.call( this, array1[col], array2[col] );
- if ( ret !== 0 ) {
- return ret;
- }
+ function multisort( table, sortList, cache ) {
+ var sortFn = [];
+ var len = sortList.length;
+ for ( var i = 0; i < len; i++ ) {
+ sortFn[i] = ( sortList[i][1] ) ? sortTextDesc : sortText;
}
- return ret;
- }
-
- // Merge sort algorithm
- // Based on http://en.literateprograms.org/Merge_sort_(JavaScript)
- function mergeSortHelper( array, begin, beginRight, end, sortList ) {
- for ( ; begin < beginRight; ++begin ) {
- if ( checkSorting( array[begin], array[beginRight], sortList ) ) {
- var v = array[begin];
- array[begin] = array[beginRight];
- var begin2 = beginRight;
- while ( begin2 + 1 < end && checkSorting( v, array[begin2 + 1], sortList ) ) {
- var tmp = array[begin2];
- array[begin2] = array[begin2 + 1];
- array[begin2 + 1] = tmp;
- ++begin2;
+ cache.normalized.sort( function ( array1, array2 ) {
+ var col, ret;
+ for ( var i = 0; i < len; i++ ) {
+ col = sortList[i][0];
+ ret = sortFn[i].call( this, array1[col], array2[col] );
+ if ( ret !== 0 ) {
+ return ret;
}
- array[begin2] = v;
}
- }
- }
-
- function mergeSort(array, begin, end, sortList) {
- var size = end - begin;
- if ( size < 2 ) {
- return;
- }
-
- var beginRight = begin + Math.floor(size / 2);
-
- mergeSort( array, begin, beginRight, sortList );
- mergeSort( array, beginRight, end, sortList );
- mergeSortHelper( array, begin, beginRight, end, sortList );
- }
-
- function multisort( table, sortList, cache ) {
- var i = sortList.length;
- mergeSort( cache.normalized, 0, cache.normalized.length, sortList );
-
+ // Fall back to index number column to ensure stable sort
+ return sortText.call( this, array1[array1.length - 1], array2[array2.length - 1] );
+ } );
return cache;
}
);
var planetsRowspan = [["Earth","6051.8"], jupiter, ["Mars","6051.8"], mercury, saturn, venus];
-var planetsRowspanII = [jupiter, mercury, saturn, ['Venus', '6371.0'], venus, ['Venus', '3390.0']];
+var planetsRowspanII = [jupiter, mercury, saturn, venus, ['Venus', '6371.0'], ['Venus', '3390.0']];
tableTest(
'Basic planet table: same value for multiple rows via rowspan',