├── .gitignore ├── ss-01.gif ├── ss-02.gif ├── .eslintrc.json ├── gettable.jquery.json ├── bower.json ├── package.json ├── LICENSE ├── jquery.gettable.min.js ├── jquery.gettable.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .vscode 3 | -------------------------------------------------------------------------------- /ss-01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anseki/jquery-gettable/HEAD/ss-01.gif -------------------------------------------------------------------------------- /ss-02.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anseki/jquery-gettable/HEAD/ss-02.gif -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": "../../_common/eslintrc.json", 4 | "env": {"browser": true, "jquery": true} 5 | } 6 | -------------------------------------------------------------------------------- /gettable.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gettable", 3 | "version": "1.0.2", 4 | "title": "getTable", 5 | "description": "The simple jQuery Plugin for easy getting the table cells that are positioned on the horizontal line, the vertical line or both lines that pass through the target cell.", 6 | "keywords": [ 7 | "table", 8 | "cell", 9 | "row", 10 | "column", 11 | "vertical", 12 | "horizontal", 13 | "header", 14 | "tr", 15 | "td" 16 | ], 17 | "dependencies": { 18 | "jquery": ">=3.0" 19 | }, 20 | "homepage": "https://anseki.github.io/jquery-gettable/", 21 | "docs": "https://anseki.github.io/jquery-gettable/", 22 | "download": "https://anseki.github.io/jquery-gettable/", 23 | "bugs": "https://github.com/anseki/jquery-gettable/issues", 24 | "licenses": "MIT", 25 | "author": { 26 | "name": "anseki", 27 | "url": "https://github.com/anseki" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-gettable", 3 | "version": "1.0.2", 4 | "description": "The simple jQuery Plugin for easy getting the table cells that are positioned on the horizontal line, the vertical line or both lines that pass through the target cell.", 5 | "keywords": [ 6 | "jquery-plugin", 7 | "ecosystem:jquery", 8 | "table", 9 | "cell", 10 | "row", 11 | "column", 12 | "vertical", 13 | "horizontal", 14 | "header", 15 | "tr", 16 | "td" 17 | ], 18 | "main": "jquery.gettable.min.js", 19 | "dependencies": { 20 | "jquery": ">=3.0" 21 | }, 22 | "homepage": "https://anseki.github.io/jquery-gettable/", 23 | "repository": { 24 | "type": "git", 25 | "url": "git://github.com/anseki/jquery-gettable.git" 26 | }, 27 | "moduleType": [], 28 | "ignore": [ 29 | "**/.*", 30 | "node_modules", 31 | "bower_components", 32 | "test", 33 | "tests" 34 | ], 35 | "license": "MIT", 36 | "authors": [ 37 | "anseki " 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-gettable", 3 | "version": "1.0.2", 4 | "title": "getTable", 5 | "description": "The simple jQuery Plugin for easy getting the table cells that are positioned on the horizontal line, the vertical line or both lines that pass through the target cell.", 6 | "keywords": [ 7 | "jquery-plugin", 8 | "ecosystem:jquery", 9 | "table", 10 | "cell", 11 | "row", 12 | "column", 13 | "vertical", 14 | "horizontal", 15 | "header", 16 | "tr", 17 | "td" 18 | ], 19 | "main": "jquery.gettable.min.js", 20 | "files": [ 21 | "jquery.gettable.min.js", 22 | "bower.json", 23 | "gettable.jquery.json" 24 | ], 25 | "dependencies": { 26 | "jquery": ">=3.0" 27 | }, 28 | "homepage": "https://anseki.github.io/jquery-gettable/", 29 | "repository": { 30 | "type": "git", 31 | "url": "git://github.com/anseki/jquery-gettable.git" 32 | }, 33 | "bugs": "https://github.com/anseki/jquery-gettable/issues", 34 | "license": "MIT", 35 | "author": { 36 | "name": "anseki", 37 | "url": "https://github.com/anseki" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 anseki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /jquery.gettable.min.js: -------------------------------------------------------------------------------- 1 | !function(n){"use strict";function e(e,t){n.each(t,function(t,o){n.inArray(o,e)<0&&e.push(o)})}function t(t,o){function r(n){var e;if(!c.rows[n])for(e=0;n>=e;e++)c.rows[e]=c.rows[e]||{cells:[],table:c};return c.rows[n]}function l(n){var e;if(!c.cols[n])for(e=0;n>=e;e++)c.cols[e]=c.cols[e]||{cells:[],table:c};return c.cols[n]}var c={rows:[],cols:[],cells:[]},s="number"==typeof o?o:y.length,u=-1,a={},i="table"===t.get(0).nodeName.toLowerCase()?t.get(0):function(){var n=t.closest("table");return n.length?n.get(0):void 0}();return i?(c.elm=i,n(i).data(N,"table:"+s),n.each(i.rows,function(e,t){var o,i,f,h,w,v,g,m,b,d=0;for(n(t).data(N,"table:"+s+",row:"+e),function(){var e=0;n.each(t.cells,function(n,t){e+=+t.colSpan||1}),e-1>u&&(u=e-1)}(),h=0;u>=h;h++)if((!a[e]||!a[e][h])&&(w=t.cells[d++])){for(n(w).data(N,"table:"+s+",cell:"+c.cells.length),f={elm:w,rows:[],cols:[],table:c,iRow:e,iCol:h},v=(+w.rowSpan||1)-1,g=(+w.colSpan||1)-1,m=0;v>=m;m++)o=r(e+m),f.rows.push(o),o.cells.push(f);for(m=0;g>=m;m++)i=l(h+m),f.cols.push(i),i.cells.push(f);for(m=1;v>=m;m++)for(a[e+m]=a[e+m]||{},b=0;g>=b;b++)a[e+m][h+b]=!0;h+=g,c.cells.push(f)}}),n.each(c.cells,function(t,o){var r=[o];n.each(o.rows.concat(o.cols),function(n,t){e(r,t.cells)}),o.xCells=r}),n.each(c.rows,function(n,e){e.cells.sort(function(n,e){return n.iCol-e.iCol})}),n.each(c.cols,function(n,e){e.cells.sort(function(n,e){return n.iRow-e.iRow})}),y[s]=c,c):null}function o(n){for(var e,t={},o=n.data(N)||"",r=/\b(\w+):(\d+)/g;null!==(e=r.exec(o));)t[e[1]]=+e[2];return t}function r(n,e){var r=o(n).table;return e||"number"!=typeof r||!y[r]?t(n,r):y[r]}function l(n){return"table"===n}function c(n){return"tr"===n}function s(n){return"td"===n||"th"===n}function u(n){return"thead"===n||"tfoot"===n||"tbody"===n}function a(n){return l(n)||c(n)||s(n)||u(n)}function i(e){return n.map(e,function(n){return n.elm})}function f(e){return n(i(e))}function h(t){var a=[];return t.each(function(){var t,f=n(this),h=f.get(0).nodeName.toLowerCase();l(h)&&(t=r(f))?e(a,i(t.cells)):c(h)&&(t=r(f))?e(a,i(t.rows[o(f).row].cells)):s(h)&&(t=r(f))?e(a,[t.cells[o(f).cell].elm]):u(h)&&(t=r(f))&&n.each(f.get(0).rows,function(r,l){e(a,i(t.rows[o(n(l)).row].cells))})}),n(a.length?a:null)}function w(t){var l=[];return t.each(function(){var t,c=n(this),u=c.get(0).nodeName.toLowerCase();s(u)&&(t=r(c))&&e(l,i(t.cells[o(c).cell].xCells))}),n(l.length?l:null)}function v(t){var a=[];return t.each(function(){var t,i=n(this),f=i.get(0).nodeName.toLowerCase();l(f)&&(t=r(i))?e(a,t.rows):c(f)&&(t=r(i))?e(a,[t.rows[o(i).row]]):s(f)&&(t=r(i))?e(a,t.cells[o(i).cell].rows):u(f)&&(t=r(i))&&e(a,n.map(i.get(0).rows,function(e){return t.rows[o(n(e)).row]}))}),a}function g(t){var a=[];return t.each(function(){var t,i=n(this),f=i.get(0).nodeName.toLowerCase();(l(f)||c(f)||u(f))&&(t=r(i))?e(a,t.cols):s(f)&&(t=r(i))&&e(a,t.cells[o(i).cell].cols)}),a}function m(e){return n.map(v(e),function(n){return f(n.cells)})}function b(t){var o=[];return n.each(v(t),function(n,t){e(o,i(t.cells))}),n(o.length?o:null)}function d(e){return n.map(g(e),function(n){return f(n.cells)})}function p(t){var o=[];return n.each(g(t),function(n,t){e(o,i(t.cells))}),n(o.length?o:null)}function C(t){var o=[];return t.each(function(){var t,l=n(this),c=l.get(0).nodeName.toLowerCase();a(c)&&(t=r(l))&&e(o,[t.elm])}),n(o.length?o:null)}function L(e){return e.each(function(){var e=n(this),t=e.get(0).nodeName.toLowerCase();a(t)&&r(e,!0)})}var N="getTable",y=[];n.fn[N]=function(n){return"cells"===n?h(this):"xCells"===n?w(this):"rows"===n?m(this):"rowsCells"===n?b(this):"cols"===n?d(this):"colsCells"===n?p(this):"table"===n?C(this):L(this)}}(jQuery); -------------------------------------------------------------------------------- /jquery.gettable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery.getTable 3 | * https://anseki.github.io/jquery-gettable/ 4 | * 5 | * Copyright (c) 2018 anseki 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | ;(function($) { // eslint-disable-line no-extra-semi 10 | 'use strict'; 11 | 12 | var APP_NAME = 'getTable', 13 | tables = []; // array of reference table 14 | 15 | function uniqueConcat(arrBase, arrNew) { 16 | $.each(arrNew, function(i, elm) { 17 | if ($.inArray(elm, arrBase) < 0) { arrBase.push(elm); } 18 | }); 19 | } 20 | 21 | function parseTable(jq, index) { 22 | var table = {rows: [], cols: [], cells: []}, 23 | iTable = typeof index === 'number' ? index : tables.length, 24 | iColMax = -1, skip = {}, // {N: {N: B}} 25 | 26 | elmTable = jq.get(0).nodeName.toLowerCase() === 'table' ? jq.get(0) : 27 | (function() { 28 | var elm = jq.closest('table'); 29 | return elm.length ? elm.get(0) : void 0; 30 | })(); 31 | if (!elmTable) { return null; } 32 | 33 | table.elm = elmTable; 34 | $(elmTable).data(APP_NAME, 'table:' + iTable); 35 | 36 | function getRow(index) { 37 | var i; 38 | if (!table.rows[index]) { 39 | for (i = 0; i <= index; i++) { 40 | table.rows[i] = table.rows[i] || {cells: [], table: table}; 41 | } 42 | } 43 | return table.rows[index]; 44 | } 45 | function getCol(index) { 46 | var i; 47 | if (!table.cols[index]) { 48 | for (i = 0; i <= index; i++) { 49 | table.cols[i] = table.cols[i] || {cells: [], table: table}; 50 | } 51 | } 52 | return table.cols[index]; 53 | } 54 | 55 | $.each(elmTable.rows, function(iRow, elmRow) { 56 | var row, col, cell, iCol, iCell = 0, elmCell, exRows, exCols, i, j; 57 | $(elmRow).data(APP_NAME, 'table:' + iTable + ',row:' + iRow); 58 | 59 | (function() { 60 | var colsLen = 0; 61 | $.each(elmRow.cells, function(i, cell) { colsLen += +cell.colSpan || 1; }); 62 | if (colsLen - 1 > iColMax) { iColMax = colsLen - 1; } 63 | })(); 64 | 65 | for (iCol = 0; iCol <= iColMax; iCol++) { 66 | if (skip[iRow] && skip[iRow][iCol]) { continue; } 67 | if ((elmCell = elmRow.cells[iCell++])) { 68 | $(elmCell).data(APP_NAME, 'table:' + iTable + ',cell:' + table.cells.length); 69 | cell = {elm: elmCell, rows: [], cols: [], table: table, iRow: iRow, iCol: iCol}; 70 | // extending via colspan="0", colgroup and rowspan="0" isn't supported. 71 | // http://dev.w3.org/html5/spec/single-page.html#attr-tdth-colspan 72 | exRows = (+elmCell.rowSpan || 1) - 1; 73 | exCols = (+elmCell.colSpan || 1) - 1; 74 | for (i = 0; i <= exRows; i++) { 75 | row = getRow(iRow + i); 76 | cell.rows.push(row); 77 | row.cells.push(cell); 78 | } 79 | for (i = 0; i <= exCols; i++) { 80 | col = getCol(iCol + i); 81 | cell.cols.push(col); 82 | col.cells.push(cell); 83 | } 84 | for (i = 1; i <= exRows; i++) { 85 | skip[iRow + i] = skip[iRow + i] || {}; 86 | for (j = 0; j <= exCols; j++) { skip[iRow + i][iCol + j] = true; } 87 | } 88 | iCol += exCols; 89 | table.cells.push(cell); 90 | } 91 | } 92 | }); 93 | 94 | // cross line cells 95 | $.each(table.cells, function(i, cell) { 96 | var xCells = [cell]; 97 | $.each(cell.rows.concat(cell.cols), 98 | function(i, rowCol) { uniqueConcat(xCells, rowCol.cells); }); 99 | cell.xCells = xCells; 100 | }); 101 | 102 | $.each(table.rows, 103 | function(i, row) { row.cells.sort(function(a, b) { return a.iCol - b.iCol; }); }); 104 | $.each(table.cols, 105 | function(i, col) { col.cells.sort(function(a, b) { return a.iRow - b.iRow; }); }); 106 | 107 | tables[iTable] = table; 108 | return table; 109 | } 110 | 111 | // {table: N, row: N, cell: N} 112 | function parseIndex(jq) { 113 | var index = {}, indexText = jq.data(APP_NAME) || '', 114 | re = /\b(\w+):(\d+)/g, matches; 115 | while ((matches = re.exec(indexText)) !== null) { 116 | index[matches[1]] = +matches[2]; 117 | } 118 | return index; 119 | } 120 | 121 | function getParse(jq, force) { 122 | var iTable = parseIndex(jq).table; 123 | return force || typeof iTable !== 'number' || !tables[iTable] ? 124 | parseTable(jq, iTable) : tables[iTable]; 125 | } 126 | 127 | function isTable(tagName) { return tagName === 'table'; } 128 | function isRow(tagName) { return tagName === 'tr'; } 129 | function isCell(tagName) { return tagName === 'td' || tagName === 'th'; } 130 | function isSection(tagName) { return tagName === 'thead' || tagName === 'tfoot' || tagName === 'tbody'; } 131 | function isAny(tagName) { return isTable(tagName) || isRow(tagName) || isCell(tagName) || isSection(tagName); } 132 | 133 | // Array of cell objects -> Array of elements 134 | function cells2Elms(cells) { return $.map(cells, function(cell) { return cell.elm; }); } 135 | // Array of cell objects -> jQuery object 136 | function cells2Jq(cells) { return $(cells2Elms(cells)); } 137 | 138 | function selectCells(jq) { 139 | var elms = []; 140 | jq.each(/* @this HTMLElement */ function() { 141 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(), table; 142 | if (isTable(tagName) && (table = getParse(that))) { 143 | uniqueConcat(elms, cells2Elms(table.cells)); 144 | } else if (isRow(tagName) && (table = getParse(that))) { 145 | uniqueConcat(elms, cells2Elms(table.rows[parseIndex(that).row].cells)); 146 | } else if (isCell(tagName) && (table = getParse(that))) { 147 | uniqueConcat(elms, [table.cells[parseIndex(that).cell].elm]); // same as that.get(0) 148 | } else if (isSection(tagName) && (table = getParse(that))) { 149 | $.each(that.get(0).rows, function(i, elmRow) { 150 | uniqueConcat(elms, cells2Elms(table.rows[parseIndex($(elmRow)).row].cells)); 151 | }); 152 | } 153 | }); 154 | return $(elms.length ? elms : null); 155 | } 156 | 157 | function selectXCells(jq) { 158 | var elms = []; 159 | jq.each(/* @this HTMLElement */ function() { 160 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(), table; 161 | if (isCell(tagName) && (table = getParse(that))) { 162 | uniqueConcat(elms, cells2Elms(table.cells[parseIndex(that).cell].xCells)); 163 | } 164 | }); 165 | return $(elms.length ? elms : null); 166 | } 167 | 168 | function selectRowsArray(jq) { 169 | var rows = []; 170 | jq.each(/* @this HTMLElement */ function() { 171 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(), table; 172 | if (isTable(tagName) && (table = getParse(that))) { 173 | uniqueConcat(rows, table.rows); 174 | } else if (isRow(tagName) && (table = getParse(that))) { 175 | uniqueConcat(rows, [table.rows[parseIndex(that).row]]); 176 | } else if (isCell(tagName) && (table = getParse(that))) { 177 | uniqueConcat(rows, table.cells[parseIndex(that).cell].rows); 178 | } else if (isSection(tagName) && (table = getParse(that))) { 179 | uniqueConcat(rows, $.map(that.get(0).rows, 180 | function(elmRow) { return table.rows[parseIndex($(elmRow)).row]; })); 181 | } 182 | }); 183 | return rows; 184 | } 185 | 186 | function selectColsArray(jq) { 187 | var cols = []; 188 | jq.each(/* @this HTMLElement */ function() { 189 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(), table; 190 | if ((isTable(tagName) || isRow(tagName) || isSection(tagName)) && 191 | (table = getParse(that))) { 192 | uniqueConcat(cols, table.cols); 193 | } else if (isCell(tagName) && (table = getParse(that))) { 194 | uniqueConcat(cols, table.cells[parseIndex(that).cell].cols); 195 | } 196 | }); 197 | return cols; 198 | } 199 | 200 | function selectRows(jq) { 201 | return $.map(selectRowsArray(jq), function(row) { return cells2Jq(row.cells); }); 202 | } 203 | 204 | function selectRowsCells(jq) { 205 | var elms = []; 206 | $.each(selectRowsArray(jq), 207 | function(i, row) { uniqueConcat(elms, cells2Elms(row.cells)); }); 208 | return $(elms.length ? elms : null); 209 | } 210 | 211 | function selectCols(jq) { 212 | return $.map(selectColsArray(jq), function(col) { return cells2Jq(col.cells); }); 213 | } 214 | 215 | function selectColsCells(jq) { 216 | var elms = []; 217 | $.each(selectColsArray(jq), 218 | function(i, col) { uniqueConcat(elms, cells2Elms(col.cells)); }); 219 | return $(elms.length ? elms : null); 220 | } 221 | 222 | function selectTable(jq) { 223 | var elms = []; 224 | jq.each(/* @this HTMLElement */ function() { 225 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(), table; 226 | if (isAny(tagName) && (table = getParse(that))) { 227 | uniqueConcat(elms, [table.elm]); // same as that.get(0) 228 | } 229 | }); 230 | return $(elms.length ? elms : null); 231 | } 232 | 233 | function reParse(jq) { 234 | return jq.each(/* @this HTMLElement */ function() { 235 | var that = $(this), tagName = that.get(0).nodeName.toLowerCase(); 236 | if (isAny(tagName)) { getParse(that, true); } 237 | }); 238 | } 239 | 240 | $.fn[APP_NAME] = function(action) { 241 | return ( 242 | /* eslint-disable no-multi-spaces */ 243 | action === 'cells' ? selectCells(this) : 244 | action === 'xCells' ? selectXCells(this) : 245 | action === 'rows' ? selectRows(this) : 246 | action === 'rowsCells' ? selectRowsCells(this) : 247 | action === 'cols' ? selectCols(this) : 248 | action === 'colsCells' ? selectColsCells(this) : 249 | action === 'table' ? selectTable(this) : 250 | reParse(this)); 251 | /* eslint-enable no-multi-spaces */ 252 | }; 253 | 254 | })(jQuery); 255 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # getTable 2 | 3 | [![npm](https://img.shields.io/npm/v/jquery-gettable.svg)](https://www.npmjs.com/package/jquery-gettable) [![GitHub issues](https://img.shields.io/github/issues/anseki/jquery-gettable.svg)](https://github.com/anseki/jquery-gettable/issues) [![David](https://img.shields.io/david/anseki/jquery-gettable.svg)](package.json) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) 4 | 5 | The simple jQuery Plugin for easy getting the table cells that are positioned on the horizontal line, the vertical line or both lines that pass through the target cell. 6 | 7 | [![ss-01](ss-01.gif)](https://anseki.github.io/jquery-gettable/) 8 | [![ss-02](ss-02.gif)](https://anseki.github.io/jquery-gettable/) 9 | 10 | **See DEMO** 11 | 12 | + getTable gets the horizontal line (`row`) and the vertical line (`col`) of the table. And it gets cells that are positioned on those lines. The handling cells that are positioned on the horizontal line is supported by `` HTML tag, but the vertical line is not supported by the HTML. 13 | + The cells that are extended by `colspan`/`rowspan` are parsed correctly. More lines pass through the extended cells (i.e. those cells catch more cells), and those cells are positioned on more lines (i.e. those cells are caught by more cells). 14 | + The horizontal line (`row`) and the vertical line (`col`) are discerned. getTable returns a jQuery object (or Array of those), therefore you can do anything you want to those. 15 | + The table is parsed via DOM, it's fast, correctly, and those data are cached. 16 | 17 | ```js 18 | // Get rows that include target cell. 19 | rows = $('td#target').getTable('rows'); 20 | 21 | // Get cols that include target cell. 22 | cols = $('td#target').getTable('cols'); 23 | 24 | // Get cells that are included in the cross line (rows and cols) of target cell. 25 | // And style those. 26 | cells = $('td#target').getTable('xCells').css('backgroundColor', 'blue'); 27 | ``` 28 | 29 | ## Getting Started 30 | Load after jQuery. 31 | 32 | ```html 33 | 34 | 35 | ``` 36 | 37 | ## Methods 38 | 39 | ### `rows` 40 | 41 | ```js 42 | rows = target.getTable('rows') 43 | ``` 44 | 45 | Return an Array that includes zero or more `row`s. The `row` is a jQuery object that includes zero or more `cell` (`` or ``) elements that are positioned on a horizontal line. The `cell`s in the `row` are sorted by position as from left to right, regardless of the HTML source order. For example, `row.eq(0)` is leftmost `cell` like the header. 46 | *(If you want to do something to all `cell`s in `rows` together (you want to do nothing to each `row`), use [`rowsCells`](#rowscells) method.)* 47 | The elements are selected according to the each element that is included in current target jQuery object. The returned `rows` is one Array that includes all of those. 48 | 49 | An element that is included in current target jQuery object is: 50 | 51 | + **`table`** (`` element) 52 | e.g. `$('table#target').getTable('rows')` 53 | All `row`s in this `table` are selected. 54 | + **`row`** (`` element) 55 | e.g. `$('tr#target').getTable('rows')` 56 | This `row` itself is selected. 57 | The `cell` elements in this `row` are not the same as `cell` elements in `` element, which includes `cell`s that are extended by `rowspan` in previous ``. 58 | + **`cell`** (``, `` or `` element) 74 | e.g. `$('thead#target').getTable('rows')` 75 | All `row`s in this `section` are selected. 76 | 77 | In any cases, the nested `table` (`table` that is included in current target) is excluded (If part of the nested `table` is target too, of course it is included). 78 | 79 | ### `rowsCells` 80 | 81 | ```js 82 | cells = target.getTable('rowsCells') 83 | ``` 84 | 85 | Return a jQuery object that includes zero or more `cell` (`
` or `` element) 59 | e.g. `$('td#target').getTable('rows')` 60 | All `row`s that include this `cell` (i.e. horizontal lines that pass through this `cell`) are selected. 61 | *(If you want both `rows` and `cols` of `cell`, use [`xCells`](#xcells) method.)* 62 | For example: 63 | 64 | ```js 65 | var hl; // keep to restore 66 | $('td').hover(function() { 67 | hl = $(this).getTable('rows')[0].addClass('highlight'); 68 | }, function() { 69 | hl.removeClass('highlight'); 70 | }); 71 | ``` 72 | 73 | + **`section`** (`
` or ``) elements that are included in all `row`s that selected by same way as [`rows`](#rows) method. The returned `cells` is one jQuery object that includes all of those. 86 | *(If you want to do something to each `row` (you want to do nothing to all `cell`s in `rows` together), use [`rows`](#rows) method.)* 87 | 88 | This is not the same as merged all `cell`s that are returned by [`rows`](#rows) method, `rowsCells` method returns unique `cell`s, duplicated elements are excluded. 89 | 90 | ### `cols` 91 | 92 | ```js 93 | cols = target.getTable('cols') 94 | ``` 95 | 96 | Return an Array that includes zero or more `col`s. The `col` is a jQuery object that includes zero or more `cell` (`` or ``) elements that are positioned on a vertical line. The `cell`s in the `col` are sorted by position as from top to bottom, regardless of the HTML source order. For example, `col.eq(0)` is uppermost `cell` like the header. 97 | *(If you want to do something to all `cell`s in `cols` together (you want to do nothing to each `col`), use [`colsCells`](#colscells) method.)* 98 | The elements are selected according to the each element that is included in current target jQuery object. The returned `cols` is one Array that includes all of those. 99 | 100 | An element that is included in current target jQuery object is: 101 | 102 | + **`table`, `row`, `section`** (``, ``, ``, `` or `` element) 103 | e.g. `$('thead#target').getTable('cols')` 104 | All `col`s in this `table` are selected. 105 | + **`cell`** (`
` or `` element) 106 | e.g. `$('td#target').getTable('cols')` 107 | All `col`s that include this `cell` (i.e. vertical lines that pass through this `cell`) are selected. 108 | *(If you want both `rows` and `cols` of `cell`, use [`xCells`](#xcells) method.)* 109 | For example: 110 | 111 | ```js 112 | var hl; // keep to restore 113 | $('td').hover(function() { 114 | hl = $(this).getTable('cols')[0].addClass('highlight'); 115 | }, function() { 116 | hl.removeClass('highlight'); 117 | }); 118 | ``` 119 | 120 | In any cases, the nested `table` (`table` that is included in current target) is excluded (If part of the nested `table` is target too, of course it is included). 121 | 122 | ### `colsCells` 123 | 124 | ```js 125 | cells = target.getTable('colsCells') 126 | ``` 127 | 128 | Return a jQuery object that includes zero or more `cell` (`` or ``) elements that are included in all `col`s that selected by same way as [`cols`](#cols) method. The returned `cells` is one jQuery object that includes all of those. 129 | *(If you want to do something to each `col` (you want to do nothing to all `cell`s in `cols` together), use [`cols`](#cols) method.)* 130 | 131 | This is not the same as merged all `cell`s that are returned by [`cols`](#cols) method, `colsCells` method returns unique `cell`s, duplicated elements are excluded. 132 | 133 | ### `cells` 134 | 135 | ```js 136 | cells = target.getTable('cells') 137 | ``` 138 | 139 | Return a jQuery object that includes zero or more `cell` (`` or ``) elements. The elements are selected according to the each element that is included in current target jQuery object. The returned `cells` is one jQuery object that includes all of those. 140 | 141 | An element that is included in current target jQuery object is: 142 | 143 | + **`table`** (`` element) 144 | e.g. `$('table#target').getTable('cells')` 145 | All `cell`s in this `table` are selected. 146 | + **`row`** (`` element) 147 | e.g. `$('tr#target').getTable('cells')` 148 | All `cell`s in this `row` are selected. 149 | This is not the same as `cell` elements in `` element, which includes `cell`s that are extended by `rowspan` in previous ``. 150 | For example: 151 | 152 | ```js 153 | $('#targetRow').getTable('cells').css('backgroundColor', 'blue'); 154 | ``` 155 | 156 | + **`cell`** (``, `` or `` element) 160 | e.g. `$('thead#target').getTable('cells')` 161 | All `cell`s in this `section` are selected. 162 | 163 | In any cases, the nested `table` (`table` that is included in current target) is excluded (If part of the nested `table` is target too, of course it is included). 164 | 165 | ### `xCells` 166 | 167 | ```js 168 | cells = target.getTable('xCells') 169 | ``` 170 | 171 | Return a jQuery object that includes zero or more `cell` (`
` or `` element) 157 | e.g. `$('td#target').getTable('cells')` 158 | This `cell` itself is selected. 159 | + **`section`** (`
` or ``) elements that are positioned on the cross line (horizontal line and vertical line) that pass through the each element that is included in current target jQuery object. The returned `cells` is one jQuery object that includes all of those. The first `cell` of that `cells` is current target. i.e. `cells.eq(0)` is a `cell` on the cross point. 172 | The elements that are not `cell` (`` or ``) are ignored. 173 | 174 | This is not the same as merged all `cell`s that are returned by [`rows`](#rows) method and [`cols`](#cols) method, `xCells` method returns unique `cell`s, duplicated elements are excluded. 175 | 176 | The nested `table` (`table` that is included in current target) is excluded (If part of the nested `table` is target too, of course it is included). 177 | 178 | For example: 179 | 180 | ```js 181 | var hl; // keep to restore 182 | $('td').hover(function() { 183 | hl = $(this).getTable('xCells').addClass('highlight'); 184 | }, function() { 185 | hl.removeClass('highlight'); 186 | }); 187 | ``` 188 | 189 | ### `table` 190 | 191 | ```js 192 | table = target.getTable('table') 193 | ``` 194 | 195 | Return a jQuery object that includes zero or more `table` (``) elements. The `
` elements that are included in current target jQuery object, and the `
` elements that have ``, ``, `` or `` elements that are included in current target jQuery object are selected. The returned `table` is one jQuery object that includes all of those (duplicated elements are excluded). 196 | 197 | ### Initialize 198 | 199 | ```js 200 | target.getTable() 201 | ``` 202 | 203 | Parse the table, and cache those data. 204 | You usually don't need to call initialize method, because getTable parses it automatically when getTable met the unknown table via other methods. And getTable caches those data, therefore parsing again is not needed. 205 | The cases of initialize method is needed are: 206 | 207 | + You want to make preparations in advance. 208 | + You changed the structure of the table that was already parsed. 209 | 210 | If the element that is included in current target jQuery object is `
`, ``, `
`, that table is parsed. If the element is part of the table (``, ``, `` or ``), the table that has those parts is parsed. 211 | i.e. these codes below are equals: 212 | 213 | ```js 214 | $('table#table1').getTable(); 215 | $('table#table1>tbody:eq(0)').getTable(); 216 | $('table#table1>tbody:eq(0)>tr:eq(0)').getTable(); 217 | $('table#table1>tbody:eq(0)>tr:eq(0)>td:eq(0)').getTable(); 218 | ``` 219 | 220 | getTable discern the nested table correctly, therefore if `` is not supported. Now, the browser that supports this is Firefox only. 225 | --------------------------------------------------------------------------------
`, ``, `
` of only the inner table is given, the outer table is not parsed. 221 | 222 | ## Note 223 | 224 | The cell extending by `colspan="0"` and `