MCPcopy Create free account
hub / github.com/breck7/scroll / __row_selector

Function __row_selector

external/.datatables.js:7196–7286  ·  view source on GitHub ↗
(settings, selector, opts)

Source from the content-addressed store, hash-verified

7194 *
7195 */
7196 var __row_selector = function (settings, selector, opts) {
7197 var rows
7198 var run = function (sel) {
7199 var selInt = _intVal(sel)
7200 var aoData = settings.aoData
7201
7202 // Short cut - selector is a number and no options provided (default is
7203 // all records, so no need to check if the index is in there, since it
7204 // must be - dev error if the index doesn't exist).
7205 if (selInt !== null && !opts) {
7206 return [selInt]
7207 }
7208
7209 if (!rows) {
7210 rows = _selector_row_indexes(settings, opts)
7211 }
7212
7213 if (selInt !== null && rows.indexOf(selInt) !== -1) {
7214 // Selector - integer
7215 return [selInt]
7216 } else if (sel === null || sel === undefined || sel === "") {
7217 // Selector - none
7218 return rows
7219 }
7220
7221 // Selector - function
7222 if (typeof sel === "function") {
7223 return rows.map(function (idx) {
7224 var row = aoData[idx]
7225 return sel(idx, row._aData, row.nTr) ? idx : null
7226 })
7227 }
7228
7229 // Selector - node
7230 if (sel.nodeName) {
7231 var rowIdx = sel._DT_RowIndex // Property added by DT for fast lookup
7232 var cellIdx = sel._DT_CellIndex
7233
7234 if (rowIdx !== undefined) {
7235 // Make sure that the row is actually still present in the table
7236 return aoData[rowIdx] && aoData[rowIdx].nTr === sel ? [rowIdx] : []
7237 } else if (cellIdx) {
7238 return aoData[cellIdx.row] && aoData[cellIdx.row].nTr === sel.parentNode ? [cellIdx.row] : []
7239 } else {
7240 var host = $(sel).closest("*[data-dt-row]")
7241 return host.length ? [host.data("dt-row")] : []
7242 }
7243 }
7244
7245 // ID selector. Want to always be able to select rows by id, regardless
7246 // of if the tr element has been created or not, so can't rely upon
7247 // jQuery here - hence a custom implementation. This does not match
7248 // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
7249 // but to select it using a CSS selector engine (like Sizzle or
7250 // querySelect) it would need to need to be escaped for some characters.
7251 // DataTables simplifies this for row selectors since you can select
7252 // only a row. A # indicates an id any anything that follows is the id -
7253 // unescaped.

Callers 1

.datatables.jsFile · 0.85

Calls 2

_selector_runFunction · 0.85
_fnSortDisplayFunction · 0.85

Tested by

no test coverage detected