* Change the order of the table * @param {object} oSettings dataTables settings object * @memberof DataTable#oApi * @todo This really needs split up!
( oSettings )
| 4334 | * @todo This really needs split up! |
| 4335 | */ |
| 4336 | function _fnSort ( oSettings ) |
| 4337 | { |
| 4338 | var |
| 4339 | i, ien, iLen, j, jLen, k, kLen, |
| 4340 | sDataType, nTh, |
| 4341 | aiOrig = [], |
| 4342 | oExtSort = DataTable.ext.type.order, |
| 4343 | aoData = oSettings.aoData, |
| 4344 | aoColumns = oSettings.aoColumns, |
| 4345 | aDataSort, data, iCol, sType, oSort, |
| 4346 | formatters = 0, |
| 4347 | sortCol, |
| 4348 | displayMaster = oSettings.aiDisplayMaster, |
| 4349 | aSort; |
| 4350 | |
| 4351 | // Resolve any column types that are unknown due to addition or invalidation |
| 4352 | // @todo Can this be moved into a 'data-ready' handler which is called when |
| 4353 | // data is going to be used in the table? |
| 4354 | _fnColumnTypes( oSettings ); |
| 4355 | |
| 4356 | aSort = _fnSortFlatten( oSettings ); |
| 4357 | |
| 4358 | for ( i=0, ien=aSort.length ; i<ien ; i++ ) { |
| 4359 | sortCol = aSort[i]; |
| 4360 | |
| 4361 | // Track if we can use the fast sort algorithm |
| 4362 | if ( sortCol.formatter ) { |
| 4363 | formatters++; |
| 4364 | } |
| 4365 | |
| 4366 | // Load the data needed for the sort, for each cell |
| 4367 | _fnSortData( oSettings, sortCol.col ); |
| 4368 | } |
| 4369 | |
| 4370 | /* No sorting required if server-side or no sorting array */ |
| 4371 | if ( _fnDataSource( oSettings ) != 'ssp' && aSort.length !== 0 ) |
| 4372 | { |
| 4373 | // Create a value - key array of the current row positions such that we can use their |
| 4374 | // current position during the sort, if values match, in order to perform stable sorting |
| 4375 | for ( i=0, iLen=displayMaster.length ; i<iLen ; i++ ) { |
| 4376 | aiOrig[ displayMaster[i] ] = i; |
| 4377 | } |
| 4378 | |
| 4379 | /* Do the sort - here we want multi-column sorting based on a given data source (column) |
| 4380 | * and sorting function (from oSort) in a certain direction. It's reasonably complex to |
| 4381 | * follow on it's own, but this is what we want (example two column sorting): |
| 4382 | * fnLocalSorting = function(a,b){ |
| 4383 | * var iTest; |
| 4384 | * iTest = oSort['string-asc']('data11', 'data12'); |
| 4385 | * if (iTest !== 0) |
| 4386 | * return iTest; |
| 4387 | * iTest = oSort['numeric-desc']('data21', 'data22'); |
| 4388 | * if (iTest !== 0) |
| 4389 | * return iTest; |
| 4390 | * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] ); |
| 4391 | * } |
| 4392 | * Basically we have a test for each sorting column, if the data in that column is equal, |
| 4393 | * test the next column. If all columns match, then we use a numeric sort on the row |
no test coverage detected