Return row data in Array

Return row data in Array

christhchristh Posts: 10Questions: 0Answers: 0
edited February 2012 in General
Hi all

I have been through the forum trying 101 different variations on what I'm trying to do and I can't fudge them to do what I want - maybe somebody can help?

I am trying to get the contents of a row where I already know the row ID that has been set via DT_RowId

What I have is...

[code]
oTable = $('#artist_gig_table').dataTable( {
bLengthChange: false,
bStateSave: false,
iDisplayLength: 10,
bSort:false,
sAjaxSource: "venue_ajax_show_gigs.php",
bProcessing: true,
aoColumns: [
{ mDataProp: "date", },
{ mDataProp: "name", sWidth: '30%'},
{ mDataProp: "description", sWidth: '30%' },
{ mDataProp: "edit" , sWidth: '30%' }
]
});
[/code]

...the table rows have a unique ID set as DT_RowId.

I then have my current click event..

[code]
$('table#artist_gig_table td a.edit').live( 'click', function (e) {
var id = $(this).parent().parent().attr('id');
var data = 'gig_id=' + id ;
$.ajax({
type: "POST",
url: "venue_ajax_edit_gig.php",
data: data,
cache: true,
success: function(data) {
var gig_id=id;
var gig_date = data[0].date;
var gig_description = data[0].description;
var gig_artist = data[0].artist;
$( "#edit_gig" ).dialog( "open" );
//alert(gig_description);
document.getElementById('gig_id_edit').value = id;
document.getElementById('datepicker_edit').value = gig_date;
document.getElementById('gig_description_edit').value = gig_description;
document.getElementById('gig_artist_edit').value = gig_artist;
},
});
});
[/code]

..which takes the DT_RowId value and passes it into the Ajax call and returns data which works perfectly.

What I am trying to do now is also pass the contents of the entire row (or just a cell in the row) to the ajax at the same time as the DT_RowId value but try as I might, I cannot get any of the data from the row.

I've tried to utilise many of the similar examples in this forum but so far have not managed to tweak any of them to do what I wish.

Help greatly appreciated.

Thanks

Chris

Replies

  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    The _ API method sounds ideal for use here:

    [code]
    $('table#artist_gig_table td a.edit').live( 'click', function (e) {
    var tr = $(this).parents('tr')[0];
    $.ajax({
    type: "POST",
    url: "venue_ajax_edit_gig.php",
    data: this._(tr)[0],
    cache: true,
    success: function(data) {
    var gig_id=id;
    var gig_date = data[0].date;
    var gig_description = data[0].description;
    var gig_artist = data[0].artist;
    $( "#edit_gig" ).dialog( "open" );
    //alert(gig_description);
    document.getElementById('gig_id_edit').value = id;
    document.getElementById('datepicker_edit').value = gig_date;
    document.getElementById('gig_description_edit').value = gig_description;
    document.getElementById('gig_artist_edit').value = gig_artist;
    },
    });
    });
    [/code]

    The underscore function will give you the data for the row passed in (including the DT_RowId parameter).

    Note I've not actually tested the above code - but it should work!

    Allan
  • christhchristh Posts: 10Questions: 0Answers: 0
    Thanks Allan

    Unfortunately that is not working for me.

    I'm getting the error Uncaught TypeError: Object http://myurl has no method '_'

    I'll keep plowing on but if you have any other suggestions they are more than welcome.

    Thanks again

    Chris
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Oops - sorry. Wrong scope. Rather than using 'this' use a reference to your DataTable :-)

    Allan
  • christhchristh Posts: 10Questions: 0Answers: 0
    Allan - fantastic, that worked - thanks
This discussion has been closed.