Newbie question

Newbie question

mooney_jmooney_j Posts: 3Questions: 0Answers: 0
edited October 2011 in General
I want to filter Table_2 with the value in the first column of a row selected in Table_1.
What am I doing wrong?

[code]
$("#Table_1 tbody").click(function(event) {
// guessing td is the node and tr is the parent node
var aPos = oTable_1.fnGetPosition( $(event.target.parentNode) );
// get the data array for the row --- don't know why [0] is needed
var aData = oTable_1.fnGetData( aPos[0] );
// hoping this is the first column value and the filter will work but it does not.
oTable_2.fnFilter( aData[0] );
}
})
[/code]

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    I am guessing this is the error:
    [code]// guessing td is the node and tr is the parent node
    var aPos = oTable_1.fnGetPosition( $(event.target.parentNode) );[/code]

    fnGetPosition expects a TR or TD, but you are giving it a $(TR) (jQuery object wrapped around TR)

    ----

    also you can skip the middle man and just put the TR directly into fnGetData

    [code] $("#Table_1 tbody").click(function(event) {
    // get the data array for the row
    var aData = oTable_1.fnGetData(event.target.parentNode );

    // hoping this is the first column value and the filter will work but it does not.
    oTable_2.fnFilter( aData[0] );
    }
    })
    [/code]

    ------------

    You should check to make sure that the event.target is what you are expecting, rather than just assuming.

    inspect it with console.log(event.target); and open the debugger.
  • mooney_jmooney_j Posts: 3Questions: 0Answers: 0
    Thanks that solved my problem.
This discussion has been closed.