* Function to run on user sort request * @param {object} settings dataTables settings object * @param {node} attachTo node to attach the handler to * @param {int} colIdx column sorting index * @param {int} addIndex Counter * @param {boolean} [shift=false] Shift click add * @param {
(settings, colIdx, addIndex, shift)
| 5485 | * @memberof DataTable#oApi |
| 5486 | */ |
| 5487 | function _fnSortAdd(settings, colIdx, addIndex, shift) { |
| 5488 | var col = settings.aoColumns[colIdx] |
| 5489 | var sorting = settings.aaSorting |
| 5490 | var asSorting = col.asSorting |
| 5491 | var nextSortIdx |
| 5492 | var next = function (a, overflow) { |
| 5493 | var idx = a._idx |
| 5494 | if (idx === undefined) { |
| 5495 | idx = asSorting.indexOf(a[1]) |
| 5496 | } |
| 5497 | |
| 5498 | return idx + 1 < asSorting.length ? idx + 1 : overflow ? null : 0 |
| 5499 | } |
| 5500 | |
| 5501 | if (!col.bSortable) { |
| 5502 | return false |
| 5503 | } |
| 5504 | |
| 5505 | // Convert to 2D array if needed |
| 5506 | if (typeof sorting[0] === "number") { |
| 5507 | sorting = settings.aaSorting = [sorting] |
| 5508 | } |
| 5509 | |
| 5510 | // If appending the sort then we are multi-column sorting |
| 5511 | if ((shift || addIndex) && settings.oFeatures.bSortMulti) { |
| 5512 | // Are we already doing some kind of sort on this column? |
| 5513 | var sortIdx = _pluck(sorting, "0").indexOf(colIdx) |
| 5514 | |
| 5515 | if (sortIdx !== -1) { |
| 5516 | // Yes, modify the sort |
| 5517 | nextSortIdx = next(sorting[sortIdx], true) |
| 5518 | |
| 5519 | if (nextSortIdx === null && sorting.length === 1) { |
| 5520 | nextSortIdx = 0 // can't remove sorting completely |
| 5521 | } |
| 5522 | |
| 5523 | if (nextSortIdx === null) { |
| 5524 | sorting.splice(sortIdx, 1) |
| 5525 | } else { |
| 5526 | sorting[sortIdx][1] = asSorting[nextSortIdx] |
| 5527 | sorting[sortIdx]._idx = nextSortIdx |
| 5528 | } |
| 5529 | } else if (shift) { |
| 5530 | // No sort on this column yet, being added by shift click |
| 5531 | // add it as itself |
| 5532 | sorting.push([colIdx, asSorting[0], 0]) |
| 5533 | sorting[sorting.length - 1]._idx = 0 |
| 5534 | } else { |
| 5535 | // No sort on this column yet, being added from a colspan |
| 5536 | // so add with same direction as first column |
| 5537 | sorting.push([colIdx, sorting[0][1], 0]) |
| 5538 | sorting[sorting.length - 1]._idx = 0 |
| 5539 | } |
| 5540 | } else if (sorting.length && sorting[0][0] == colIdx) { |
| 5541 | // Single column - already sorting on this column, modify the sort |
| 5542 | nextSortIdx = next(sorting[0]) |
| 5543 | |
| 5544 | sorting.length = 1 |
no test coverage detected