Detecting when a row is selected (single row)

Detecting when a row is selected (single row)

luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
edited January 2014 in DataTables 1.9
Hi,

I'm looking to display information on a secondary div when a row is selected. Be aware that the data use ajax to retrieve data, therefore I can't use the...
[code]

$("#HomeSprintsT tr").click( function( e ) {
updateDiv(id);
});
[/code]

since tr is not created until data is received!

I also tried

[code]

"sAjaxSource": "Data.php?tbl=5&",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
//Add Click event
nRow.click(function(e){
updateDiv(nRow.id);
});
}

[/code]
with no success...

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Use a delegated event: `$('#HomeSpritesT tbody').on( 'click', 'tr', function (e) {...} );` .

    See also the top FAQ: http://datatables.net/faqs .

    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    [code]
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    //Add Click event
    $('#HomeSpritesT tbody').on( 'click', function (e) {
    alert('delegate worked!');
    });

    }
    [/code]

    did not worked... nor

    [code]

    $(document).ready(function() {
    $('#HomeSpritesT tbody').on( 'click', function (e) {
    alert('delegate worked!');
    });

    [/code]

    I suspect because the table is not created (or removed during a refresh)... should I try after the complete event of the table?
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    I also tried
    [code]
    "fnInitComplete": function( nRow, aData, iDisplayIndex ) {
    //Add Click event
    $('#HomeSpritesT tbody').on( 'click','tr', function (e) {
    alert('delegate worked!');
    });

    }
    [/code]

    with no success :(
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Can you link us to a test page showing the problem please? That should work! (jQuery 1.7+).

    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    http://162.242.155.240/codeTracker/App.php

    email lortega@microkey.com
    pass luis

    section Home, then Sprints (left side)

    file App.js and App.php
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    > $('#HomeSpritesT tbody').on( 'click','tr', function (e) {

    Typo - it should be:

    [code]
    $('#HomeSprintsT tbody').on( 'click','tr', function (e) {
    [/code]

    Sprints, not Sprites :-)

    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    AAAAaahhhhhhh!!!!! lol I have no clue what I was thinking!!!!

    Thanks a lot Sir!
This discussion has been closed.