fnGetData - Using elements to get back row data...

fnGetData - Using elements to get back row data...

talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
edited February 2010 in General
I'm trying to get data from a table by clicking a button that is within a cell in that row... So what I thought I would do is pass the TR of that row to fnGetData by using jQuery to grab the parent of the td the button is in. So I have the following:
[code]
...

<?=$class['CLASS_ID']?>
<?=$class['CALL_NUMBER']?>
Remove

...
[/code]
[code]
function removeClass(element)
{
var row = classTable.fnGetData(element);
var id = row[0];
...
}
[/code]

I would think this would work... I've tried variants such as fnGetData(element[0]) since technically jQuery returns an array but I always get this same error. oSettings.aoData[iRow] is undefined. I'm using 1.6.1... Any ideas? all the examples I found so far use "this" passed directly to the fnGetData function where this is the tr element that has been clicked.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I've just this on one of my demo tables "oTable.fnGetData( $('#example tbody tr:eq(3)')[0] );" which appears to do the trick nicely. I think your understanding of how fnGetData is exactly the same as mine - so there is something funny going on here! You are right that you can't just pass pass a jQuery object, you need to pass a DOM element. If you 'console.log' the 'element' variable - does that match up with what you would expect (i.e. the TR)? You could use the 'filter' option of 'parent()' to get the TR: http://api.jquery.com/parent/

    Thanks,
    Allan
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    I changed my code to read
    [code]
    function removeClass(element)
    {
    console.log(element[0]);
    var row = classTable.fnGetData(element[0]);
    console.log(row);
    var id = row[0];
    console.log(id);
    ...
    }
    [/code]
    Of course this is what I get back


    oSettings.aoData[iRow] is undefined
    fnGetData()jquery...bles.js (line 1531)
    removeClass()classM...ment.js (line 114)
    function onclick(event) { removeClass($($(this).parent(":first")).parent(":first")); }()Allan?...t/seq/4 (line 2)
    [Break on this error] return oSettings.aoData[iRow]._aData;

    Meaning that It is only getting to the first console.log() showing the TR as I expected to find however I had tried to do this :first and of course it returns the exact same results... seeing as each item

    I've tried a few variations such as
    $($(this).parent(':first')).parent(':first')
    $($(this).parent(':first')).parent(':first')[0]
    $('#classManagement tr:eq(1)')[0]

    and in those cases I manipulated the "element" variable to where it only returns 1 item... the same "" that has been showing up. I'm at a loss on this one. I'm not quite sure what's going on... I can't even give it a normal TR and it work...

    Maybe it's a stupid mistake somewhere else... Here is my full js file http://anatolefaci.com/dev/Allan/js/classManagement.js as it stands and HTML... Unfortunatly I'm going to have to find a plan "B" as with more times than not... I'm under a tight deadline of tonight to get this feature released.

    [code]

    Class Management





    ID
    Class




    <?foreach(Application::$layout->classes as $class)
    {
    ?>

    <?=$class['CLASS_ID']?>
    <?=$class['CALL_NUMBER']?>
    Remove

    <?
    }
    ?>



    ID
    Class





    Use a csv file to upload multiple classes at once. To see a sample csv file. Click here.
    Upload Classes:

    Upload



    [/code]
  • talkitivewizardtalkitivewizard Posts: 30Questions: 0Answers: 0
    Figured it out... turns out I had 2 copies of DataTables on my system. one was 1.6.0(beta) and the other was 1.6.1... unfortunately I was pointing to 1.6.0(beta). Everything works now :D. sorry about the headache and false alarm. I feel another Donation is in order for your hard work and all the crap you put up with :D.
This discussion has been closed.