fnOpen with jQuery html [with fix]
fnOpen with jQuery html [with fix]
I wanted to use the fnOpen function, only with jQuery html instead of string html, when I noticed this isn't possible. So I made the following change to fnOpen (line 1651):
[code] if(sHtml.jquery){
nNewCell.appendChild(sHtml.clone()[0]);
}else{
nNewCell.innerHTML = sHtml;
}[/code]
Note: when using jQuery html the id is usually used as identifier, but this will be cloned too. It's therefor not correct to include id's in this jQuery. I solved it with: [code]$("#example").hide().children().clone().show();[/code]
[code] if(sHtml.jquery){
nNewCell.appendChild(sHtml.clone()[0]);
}else{
nNewCell.innerHTML = sHtml;
}[/code]
Note: when using jQuery html the id is usually used as identifier, but this will be cloned too. It's therefor not correct to include id's in this jQuery. I solved it with: [code]$("#example").hide().children().clone().show();[/code]
This discussion has been closed.
Replies
[code] if(sHtml.jquery){
nNewCell.appendChild(sHtml.clone()[0]);
}else if(typeof sHtml == "object"){
nNewCell.appendChild(sHtml);
}else{
nNewCell.innerHTML = sHtml;
}
[/code]
Allan
Regards,
Allan
Hope to see this feature implemented in the next release.
Here's what I'm trying to do:
[code]
// Open the details row
dt.fnOpen(nTr, 'Test: ', "details_row");
// Cache the contents of the details row (will preserve form values)
var cached_content = $(nTr).next().find("td").contents().remove();
dt.fnClose(nTr);
// Reopen the details row with the cached content
dt.fnOpen(nTr, cached_content, "details_row");
[/code]
Here's the error I get:
[code]
Could not convert JavaScript argument arg 0 [nsIDOMHTMLTableCellElement.appendChild]
[/code]
Looking at the source and doing a little bit of testing, it looks like you could support this type of use by changing:
[code]
if( mHtml.jquery !== undefined || typeof mHtml === "object" )
{
nNewCell.appendChild( mHtml );
}
else
{
nNewCell.innerHTML = mHtml;
}
[/code]
to the simpler form:
[code]
$(nNewCell).html( mHtml );
[/code]
Alternately, you could cut the whole creation process down to:
[code]
var nNewCell = $('', {
"class" : sClass,
"colspan" : _fnVisbleColumns( oSettings )
}).html(mHtml);
var nNewRow = $('').append(nNewCell)[0];
[/code]
http://jsperf.com/jquery-append-row
Another alternative to the current approach that's slightly faster for basic strings (only 1 condition vs 2), but allows for more flexibility for jQuery objects:
[code]
if (typeof mHtml === "string")
{
nNewCell.innerHTML = mHtml;
}
else
{
$(nNewCell).html(mHtml);
}
[/code]
Regards,
Allan