fnCreatedCell with jQuery(document).ready(function()

fnCreatedCell with jQuery(document).ready(function()

rwalktheplankrwalktheplank Posts: 2Questions: 1Answers: 0
edited July 2012 in TableTools
I am currently using a (document).ready(function() within the fnCreatedCell to generate some hidden trs(using .insertAfter) that i want shown when the user clicks.

The function works until I "submit form information"... i.e. change how many items are shown, enter a search, or click on a paging item from the user side.

The hidden trs won't generate if I remove the document.ready framework.

So my question(s) is(are):

1) Is there an alternative to the document.ready framework i should be using?
2) Should I use this .insertAfter function in a different callback?

[code] {"aTargets": [ "objective" ],
"bSearchable": false,
"bSortable": false,
"sClass": "highlight",
"fnCreatedCell":
function (nTd, sData, oData, iRow, iCol) {

jQuery(nTd).css('cursor','pointer')

//jQuery(document).ready(function() {
jQuery(''
+''+oData[2]+''
+''
+'Fund Info'
+'Symbol: '+oData[1]+''
+'Name: '+oData[2]+''
+'Objective: '+oData[0]+''
+'Assets: '+oData[4]+''
+'Exp. Ratio: '+oData[11]+''
+''
+''
+'Fund Performance'
+'Quarter: '+oData[5]+''
+'1 Year: '+oData[6]+''
+'3 Year: '+oData[7]+''
+'5 Year: '+oData[8]+''
+'10 Year: '+oData[9]+''
+''
+''
+jQuery("."+sData+"-showit").html()
+''
+'').insertAfter("tr."+oData[1])
//});

jQuery(nTd).click(function() {
if(jQuery('tr.'+oData[1]+'-showit2').is(':hidden')){
jQuery(this).parent('tr').css({'color':'#cccccc'})
jQuery('tr.'+oData[1]+' td.highlight').css({'color':'#000000'})
jQuery(this).show('slow').css({'border-bottom-color':'#FFF899','background-color':'#FFF899'})
jQuery('tr.'+oData[1]+'-showit2').show('slow');
}else{
jQuery(this).parent('tr').css({'color':'#000000'})
jQuery(this).css({'border-bottom-color':'#cccccc','background-color':''})
jQuery('tr.'+oData[1]+'-showit2').hide();
}
[/code]

Any help is appreciated. I'm a bit new to jQuery, and I'm using this on a Wordpress site, so thats why all the $s are replaced with jQuery.
});

Replies

  • allanallan Posts: 61,759Questions: 1Answers: 10,111 Site admin
    > 1) Is there an alternative to the document.ready framework i should be using?

    I'd say only use one document ready function, and your DataTables initialisation should be in that.

    > 2) Should I use this .insertAfter function in a different callback?

    Yes - you want to use fnDrawCallback (or fnRowCallback ) since DataTables will remove any elements in the tbody on a draw and then insert the TR elements for the rows it wants to display.

    Allan
This discussion has been closed.