* Change the order of the table * @param {object} oSettings dataTables settings object * @memberof DataTable#oApi
(oSettings, col, dir)
| 5349 | * @memberof DataTable#oApi |
| 5350 | */ |
| 5351 | function _fnSort(oSettings, col, dir) { |
| 5352 | var i, |
| 5353 | ien, |
| 5354 | iLen, |
| 5355 | aiOrig = [], |
| 5356 | extSort = DataTable.ext.type.order, |
| 5357 | aoData = oSettings.aoData, |
| 5358 | sortCol, |
| 5359 | displayMaster = oSettings.aiDisplayMaster, |
| 5360 | aSort |
| 5361 | |
| 5362 | // Allow a specific column to be sorted, which will _not_ alter the display |
| 5363 | // master |
| 5364 | if (col !== undefined) { |
| 5365 | var srcCol = oSettings.aoColumns[col] |
| 5366 | aSort = [ |
| 5367 | { |
| 5368 | src: col, |
| 5369 | col: col, |
| 5370 | dir: dir, |
| 5371 | index: 0, |
| 5372 | type: srcCol.sType, |
| 5373 | formatter: extSort[srcCol.sType + "-pre"], |
| 5374 | sorter: extSort[srcCol.sType + "-" + dir] |
| 5375 | } |
| 5376 | ] |
| 5377 | displayMaster = displayMaster.slice() |
| 5378 | } else { |
| 5379 | aSort = _fnSortFlatten(oSettings) |
| 5380 | } |
| 5381 | |
| 5382 | for (i = 0, ien = aSort.length; i < ien; i++) { |
| 5383 | sortCol = aSort[i] |
| 5384 | |
| 5385 | // Load the data needed for the sort, for each cell |
| 5386 | _fnSortData(oSettings, sortCol.col) |
| 5387 | } |
| 5388 | |
| 5389 | /* No sorting required if server-side or no sorting array */ |
| 5390 | if (_fnDataSource(oSettings) != "ssp" && aSort.length !== 0) { |
| 5391 | // Reset the initial positions on each pass so we get a stable sort |
| 5392 | for (i = 0, iLen = displayMaster.length; i < iLen; i++) { |
| 5393 | aiOrig[i] = i |
| 5394 | } |
| 5395 | |
| 5396 | // If the first sort is desc, then reverse the array to preserve original |
| 5397 | // order, just in reverse |
| 5398 | if (aSort.length && aSort[0].dir === "desc" && oSettings.orderDescReverse) { |
| 5399 | aiOrig.reverse() |
| 5400 | } |
| 5401 | |
| 5402 | /* Do the sort - here we want multi-column sorting based on a given data source (column) |
| 5403 | * and sorting function (from oSort) in a certain direction. It's reasonably complex to |
| 5404 | * follow on it's own, but this is what we want (example two column sorting): |
| 5405 | * fnLocalSorting = function(a,b){ |
| 5406 | * var test; |
| 5407 | * test = oSort['string-asc']('data11', 'data12'); |
| 5408 | * if (test !== 0) |
no test coverage detected