Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting an arbitrary cell in a table by row and column number

I have a large table, and I need to be able to select a specific cell using it's cell/row coordinates.

What's the most elegant way of doing this using jQuery?

like image 211
Acorn Avatar asked May 08 '11 22:05

Acorn


People also ask

How do I get the cell value based on row and column numbers in Excel?

Please enter this formula: =INDIRECT(ADDRESS(F1,F2)), and press Enter key to get the result, see screenshot: Note: In the above formula, F1 and F2 indicate the row number and column number, you can change them to your need.

How do you select a specific cell in a table?

You can also click anywhere in the table column, and then press CTRL+SPACEBAR, or you can click the first cell in the table column, and then press CTRL+SHIFT+DOWN ARROW.

What is the best way to select a row with a certain value from a column in Excel?

Or click on any cell in the column and then press Ctrl + Space. Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

How do I select only certain cells in Excel?

Press F5 or CTRL+G to launch the Go To dialog. In the Go to list, click the name of the cell or range that you want to select, or type the cell reference in the Reference box, then press OK. For example, in the Reference box, type B3 to select that cell, or type B1:B3 to select a range of cells.


1 Answers

This is one case where I think using native JavaScript actually makes the code easier to understand:

var table = $("#table")[0];
var cell = table.rows[1].cells[1]; // This is a DOM "TD" element
var $cell = $(cell); // Now it's a jQuery object.

Note that just selecting the table element will make rows include those rows in your thead (and tfoot). What you probably want is:

var table = $("#table tbody")[0];
/* remaining code from above */

Here's an example: http://jsfiddle.net/CgqQt/

like image 164
Andrew Whitaker Avatar answered Oct 12 '22 00:10

Andrew Whitaker