Reputation: 791
I load a jQuery datatables using JSON. One of the fields in a row is the legend. Basically, I would like to have a "show/hide" legend instead of having the full legend text. What can I do?
Thanks!
Updated with an example: http://jsfiddle.net/fDavN/5592/
Please check code on jsfiddle (quite long)
Upvotes: 2
Views: 1189
Reputation: 4320
If you want add this functionality to every row, you should check datatables documentation: show-hide
In my project (server-side processing) I did it by call sDefaultContent
(on first column) on aoColumns
definition:
"aoColumns": [
{
"mDataProp": null,
"sClass": "control center",
"sDefaultContent": '<img src="some_image_url">'
},
//...
]
and prepare function which append some data to clicked row:
$('#datatables_selector').live( 'click', function () {
var nTr = this.parentNode;
var i = $.inArray( nTr, anOpen );
if ( i === -1 ) {
$('img', this).attr( 'src', "some_image_url" );
var nDetailsRow = oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push( nTr );
}
else {
$('img', this).attr( 'src', "some_image_url" );
$('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
} );
}
} );
function fnFormatDetails( oTable, nTr ){
var oData = oTable.fnGetData( nTr );
var sOut = 'some html for input data: <div>, <table> etc';
return sOut;
}
Upvotes: 1