ajax source

ajax source

lvalerolvalero Posts: 13Questions: 0Answers: 0
edited January 2010 in General
Hello,

how can i get a column value of a selected row using ajax source ?

Regards.

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    http://datatables.net/api#fnGetData ? Pass it the TR element you want the data for and it gives you an array.

    Regards,
    Allan
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    edited January 2010
    Hello,

    It seems that the :
    [code]$('#example2 tbody td').click( function () [/code]

    is not catched for an ajax source, that one is catched :

    [code]
    $('#example2 thead th').click( function () {
    alert ('click');
    } );
    [/code]

    Regards,
    Lionel.
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    Yeaah !

    I have found a way to do so, using the livequey plugin :

    Actually i needed to get the value of all first TD when clicking on them :

    [code]
    $('#example2 tbody td:first-child').livequery('click', function(event) {
    $('#idselect2').val(this.innerHTML);
    } );
    [/code]

    Regards
  • pwc1011pwc1011 Posts: 62Questions: 0Answers: 0
    This brings up an interesting thought, instead of using a function before draw to go back and loop through to add the click event, it seems that using a live binder to the column would be simpler and possibly less overhead.

    Do I understand this correctly?

    Thanks,
    Patrick
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    Yes.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Yup - live events are a great way to do this. I do like them :-)

    Another option is to use fnGetNodes() ( http://datatables.net/examples/advanced_init/events_post_init.html ). And possibly fnDrawCallback.

    Allan
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    Actually it does not work properly,

    when i have many rows, and if i click on the "next" button to display following rows, it still works, but when i click on "previous" the livequery stops working.

    Regards.
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    Fixed !

    I switch from livequery plugin to native live :
    [code]
    $('#example tbody td:first-child').live('click', function() {
    $('#idselect').val(this.innerHTML);
    });

    $('#example tbody td:first-child').live('mouseover mouseout', function(event) {
    if (event.type == 'mouseover') {
    $(this).addClass('dessus');
    } else {
    $(this).removeClass('dessus');
    }
    });
    [/code]
This discussion has been closed.