* Build a data source object from an HTML row, reading the contents of the * cells that are in the row. * * @param {object} settings DataTables settings object * @param {node|object} TR element from which to read data or existing row * object from which to re-read the data from the cells
(settings, row, colIdx, d)
| 2726 | * @memberof DataTable#oApi |
| 2727 | */ |
| 2728 | function _fnGetRowElements(settings, row, colIdx, d) { |
| 2729 | var tds = [], |
| 2730 | td = row.firstChild, |
| 2731 | name, |
| 2732 | col, |
| 2733 | i = 0, |
| 2734 | contents, |
| 2735 | columns = settings.aoColumns, |
| 2736 | objectRead = settings._rowReadObject |
| 2737 | |
| 2738 | // Allow the data object to be passed in, or construct |
| 2739 | d = d !== undefined ? d : objectRead ? {} : [] |
| 2740 | |
| 2741 | var attr = function (str, td) { |
| 2742 | if (typeof str === "string") { |
| 2743 | var idx = str.indexOf("@") |
| 2744 | |
| 2745 | if (idx !== -1) { |
| 2746 | var attr = str.substring(idx + 1) |
| 2747 | var setter = _fnSetObjectDataFn(str) |
| 2748 | setter(d, td.getAttribute(attr)) |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | // Read data from a cell and store into the data object |
| 2754 | var cellProcess = function (cell) { |
| 2755 | if (colIdx === undefined || colIdx === i) { |
| 2756 | col = columns[i] |
| 2757 | contents = cell.innerHTML.trim() |
| 2758 | |
| 2759 | if (col && col._bAttrSrc) { |
| 2760 | var setter = _fnSetObjectDataFn(col.mData._) |
| 2761 | setter(d, contents) |
| 2762 | |
| 2763 | attr(col.mData.sort, cell) |
| 2764 | attr(col.mData.type, cell) |
| 2765 | attr(col.mData.filter, cell) |
| 2766 | } else { |
| 2767 | // Depending on the `data` option for the columns the data can |
| 2768 | // be read to either an object or an array. |
| 2769 | if (objectRead) { |
| 2770 | if (!col._setter) { |
| 2771 | // Cache the setter function |
| 2772 | col._setter = _fnSetObjectDataFn(col.mData) |
| 2773 | } |
| 2774 | col._setter(d, contents) |
| 2775 | } else { |
| 2776 | d[i] = contents |
| 2777 | } |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | i++ |
| 2782 | } |
| 2783 | |
| 2784 | if (td) { |
| 2785 | // `tr` element was passed in |
no test coverage detected