user1552172
user1552172

Reputation: 676

Get text from row column

I am only getting back the entire row as a object, what I am trying to get is the second column's row data.

    $('#table_id tbody').on('click', 'tr', function (e) {
    var nTr   = this;
    var i     = $.inArray(nTr, anOpen);
    var aPos  = oTable.fnGetPosition(this);
    var aData = oTable.fnGetData(aPos[0]);

    console.log(aData[0]);
    if (i == -1) {
        $(this).addClass('row_selected');
        var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr, 1), 'details');
        $('div.innerDetails', nDetailsRow).slideDown();
        anOpen.push(nTr);
    }
    else {
        $(this).removeClass('row_selected');
        $('div.innerDetails', $(nTr).next()[0]).slideUp(function () {
            oTable.fnClose(nTr);
            anOpen.splice(i, 1);
        });
    }
});

Upvotes: 0

Views: 1331

Answers (2)

kaushik0033
kaushik0033

Reputation: 677

var table = document.getElementsByTagName("table")[0];

var rows = table.getElementsByTagName("tr");

for(var i = 0; i < rows.length; i++) {

    var cell = rows[i].getElementsByTagName('td')[2];
    var cellText = cell.childNodes[0];
    if(cellText.data == '02/06/2010') {
        // do something with cell
    }
}

Try it here http://jsfiddle.net/ANsUq/

Upvotes: 0

Jakub Kotrs
Jakub Kotrs

Reputation: 6229

$('#table_id tbody').on('click', 'tr', function (e) {
    var secondColumn = this.cells[1]; // returns HTMLTableCellElement

Now you can work with secondColumn to get all the data you need, such as secondColumn.innerHTML. If you need to work with the cell in jQuery, just use

    var secondColumn = $(this.cells[1]);

instead.

Upvotes: 1

Related Questions