capture cell values for display elsewhere

capture cell values for display elsewhere

dnagirldnagirl Posts: 36Questions: 2Answers: 0
edited April 2011 in TableTools
I have this dataTable setup:

[code]
$(document).ready(function() {
$('#RectifiedCount').dataTable( {
"bJQueryUI": true,
"bProcessing": true,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bStateSave": true,
"sDom": '<"H"if>tr<"F"lTp>',
"aoColumns":[
{'sname':'count_id', 'sType':'numeric', 'bVisible':false},
{'sName':'count_type', 'sType':'string','bVisible':true},
{'sName':'count_date', 'sType':'date','bVisible':true},
{'sName':'count_count', 'sType':'numeric','bVisible':true},
{'sName':'count_notes', 'sType':'string','bVisible':true}
],
"oTableTools": {
"sRowSelect": "single",
"sSwfPath": "media/swf/copy_cvs_xls_pdf.swf",
"aButtons": [ {sExtends :'select_none' , 'sButtonText':'Clear Selection'}],
"fnRowSelected": function(node){
var c=$(node).children();
if($(c[0]).text()=='Delivery') return ;
$('select[name="count_type"]').val($(c[0]).text());
$('input[name="count_date"]').val($(c[1]).text());
$('input[name="count_count"]').val($(c[2]).text());
$('textarea[name="count_notes"]').val($(c[3]).text());
}
},
'sScrollX':'100%'
});
});
[/code]

When I select a row, I want to copy the values of the cells of that row into some form fields that are named the same as the 'sName' attributes. I have 2 questions:

- is there a TableTools method for accessing the value of a cell in a selected row? Something like `node['sName_whatever'].value` would be nice.
- how can I get the value of the cells where bVisible=false?

Thanks,
Jen

Replies

  • gloosemogloosemo Posts: 27Questions: 1Answers: 0
    i have the same problem. theres gotta be an easy way to get the value or other attributes i.e. id/name/class
  • janiscmbpjaniscmbp Posts: 6Questions: 0Answers: 0
    I have a button to open a dialog for defining something for the chosen rows. Following adds second column content of selected rows to a variable to use (where there is now an alert()). Perhaps something like this is what you are looking for. I am miserable with javascript, but that seems to work.
    [code]
    {
    "sExtends": "text",
    "sButtonText": "DoSomething",
    "fnClick" : function ( nButton, oConfig, oFlash ) {
    var ids;
    ids = "";
    $('.DTTT_selected td:nth-child(2)').each(function() {
    ids+= $(this).text()+",";
    });
    alert(ids);
    }
    [/code]
  • dnagirldnagirl Posts: 36Questions: 2Answers: 0
    I haven't been here in a while, but seen as other people have had this question, this is what I ended up with as a solution. Hopefully it will be helpful to someone else.

    Set TableTools.fnRowSelected to something like this:
    [code]

    "fnRowSelected": function(node){
    aData = rctable.fnGetData(node); //this is how to get the data from a table row

    //set some form fields with data from the selected table row
    $('input[name="count_id"]').val(aData[0]);//hidden column, hidden form field
    $('select#count_type option:contains('+ aData[1]+')').attr('selected',true); //regular column, form select box
    $('input#count_date').val(aData[2]); //regular column, form input box
    $('input#fish_count').val(aData[3]);
    $('textarea#count_notes').val(aData[4]);
    }
    [/code]
This discussion has been closed.