[SOLVED]fnRowSelected gives me a undefined array

[SOLVED]fnRowSelected gives me a undefined array

DenonthDenonth Posts: 76Questions: 0Answers: 0
edited October 2012 in General
Hi all,

I need to be able to read cell from the certain column.
I am using this:

[code]
"fnRowSelected": function ( node ) {
alert( 'The row with ID '+ node[1]+' was selected' );
}
[/code]

But I can't read anything from the node. It is always undefined. how can I access certain column from the node?

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    The documentation ( http://datatables.net/extras/tabletools/initialisation#fnRowSelected ) says of the parameter passed in:

    > 1. node : TR element which was selected

    So I don't understand what `node[1]` is meant to be since its not an array? `node.id` would give you the id...

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Greetings Allan, I am glad that you have answered my question because I have tried it as it is in documentation [code]node.id[/code] in my case I need something as [code]node.Latitude[/code] as my column Latitude is hidden and I need its value.

    So that's why I tried to experiment with bunch of different approaches but non of that is working and I am always getting [code]undefined[/code] value.

    So any idea?
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > node.Latitude

    Have you attached `Latitude` to the node?? Or is `Latitude` in the data source object for the row? I think you want `table.fnGetData(node).Latitude` .

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    I don't know what you think with attaching Latitude to the node but anyway I tried your second example and I am getting a "table" is not defined:

    [code]alert( 'The row with Latitude '+ table.fnGetData(node).Latitude +' was selected' );[/code]

    So I tried with defining datatable like [code]var oTable=...[/code] and still the same thing.

    So when you wrote "table" I need to write what?
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > So when you wrote "table" I need to write what?

    No - use your DataTables instance...

    If that doesn't work please link us to a page showing the problem.

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    I am developing page on a local server so I can't sent you a link.

    But at least I can give you more information, so this is how it all looks like:

    [code]
    var oTable = $('#stops').dataTable( {
    "sDom": 'T,lfrtip',
    "oTableTools": {
    "sSwfPath": "../swf/copy_csv_xls_pdf.swf",
    "sRowSelect": "single",

    "fnRowSelected": function ( node ) {
    alert( 'The row with Latitude '+ oTable.fnGetData(node).Latitude +' was selected' );
    }
    },
    "bProcessing": true,
    "bServerSide": true,
    "aoColumnDefs": [
    { "bVisible": false, "aTargets": [ 7 , 8] }
    ],
    "sPaginationType": "full_numbers",
    "bSort": false,
    "bDeferRender": true,
    "sAjaxSource": new_url ,
    "bDestroy": true,

    } )
    ;

    [/code]

    And error that I'm getting is this:
    [code]
    Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
    [/code]
    at [code] jquery.dataTables.js:5522 [/code]
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    http://live.datatables.net
    http://jsfiddle.net

    Are both available to recreate an example test case so wee can discover exactly what is going on.
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    edited October 2012
    I have made some example but I can't make it work on your example. I mean row selecting is not working on this example.

    http://live.datatables.net/isahip/4/edit

    Do I at least have everything that I need?
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Did you look at the Javascript console in your browser? The script loading order was incorrect:

    http://live.datatables.net/isahip/5/edit

    Now it has a column count issue - which is correct, the HTML has 5 columns, your aoColumns uses 9 columns.
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    I just removed that aoColumns but still there is a problem and click event is not working.

    Can you be more specific with

    [quote]allan said: The script loading order was incorrect[/quote]

    What do you mean?
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Your load order was:

    1. DataTables
    2. TableTools
    3. jQuery

    Which version did you save it to?
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Alan,

    This is my last change
    http://live.datatables.net/isahip/7/edit
    I really don't understand you with that load order.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Okay - let's forget the load order, that's not important.

    So annoyingly it appears the TableTools documentation is slightly wrong - it is passing an array :-(. That might have been a recent change. I'll need too look into it. Sorry about that.

    Here is a working test case: http://live.datatables.net/isahip/8/edit

    Allan
  • DenonthDenonth Posts: 76Questions: 0Answers: 0
    Finally it is working. Thank you Allan.
This discussion has been closed.