DataTables logo DataTables

via Ad Packs
fnCreatedCell with jQuery(document).ready(function()
  • 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?

    			{"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('<tr class="'+oData[1]+'-showit2 hidden"><td colspan="13" style="background:#FFF899; padding:10px;">'
    							+'<h1>'+oData[2]+'</h1>'
    							+'<div style="display:inline-block; padding-right:20px" class="fundinfo">'
    							+'<h2>Fund Info</h2>'
    							+'<p>Symbol: '+oData[1]+'</p>'
    							+'<p>Name: '+oData[2]+'</p>'
    							+'<p>Objective: '+oData[0]+'</p>'
    							+'<p>Assets: '+oData[4]+'</p>'
    							+'<p>Exp. Ratio: '+oData[11]+'</p>'
    							+'</div>'
    							+'<div style="display:inline-block;" class="fundperf">'
    							+'<h2>Fund Performance</h2>'
    							+'<p>Quarter: '+oData[5]+'</p>'
    							+'<p>1 Year: '+oData[6]+'</p>'
    							+'<p>3 Year: '+oData[7]+'</p>'
    							+'<p>5 Year: '+oData[8]+'</p>'
    							+'<p>10 Year: '+oData[9]+'</p>'
    							+'</div>'
    							+'<div class="bench">'
    							+jQuery("."+sData+"-showit").html()
    							+'</div>'
    							+'</td><tr>').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();
    							}
    

    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.
    });
  • allanallan
    Posts: 15,874
    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.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion