Drill down rows opened after init
Drill down rows opened after init
shiftymccool
Posts: 19Questions: 1Answers: 0
Hello again,
I'm having a blast working with this plugin. I've got a feature that I'm trying to implement that I can't quite figure out how to do. I have drill-down rows working with a click. What I'm looking for is to have a drill-down shown by default based on a column value.
Basically, if there is a value of "Not Resulted" in the column, show the section, if the value is anything else, keep it hidden.
I've been messing with the different callback functions with no luck and it seems, now, like I might be over-thinking it.
Anybody got any advice?
Thanks!
I'm having a blast working with this plugin. I've got a feature that I'm trying to implement that I can't quite figure out how to do. I have drill-down rows working with a click. What I'm looking for is to have a drill-down shown by default based on a column value.
Basically, if there is a value of "Not Resulted" in the column, show the section, if the value is anything else, keep it hidden.
I've been messing with the different callback functions with no luck and it seems, now, like I might be over-thinking it.
Anybody got any advice?
Thanks!
This discussion has been closed.
Replies
[code]
"fnDrawCallback": function () {
var that = this;
$('#myTable tbody tr').each( function () {
var data = that.fnGetData( this );
if ( data[0] === "Not Resulted" ) {
table.fnOpen( this, 'data' );
}
}
}
[/code]
Allan
This looks like what I need, and it seems to be in the right place, but there's something not quite right. Even though the data is found (I'm logging output to console and it's finding my two records with "Not Resulted") the section still does not open.
My guess is that I didn't give you enough data initially. I'm using mData (the node I need is called "resulted") and a separate function that I found in an example somewhere to open my sections. Here is the code:
[code]
var activitiesTable = $('#activitiesGrid').dataTable( {........} );
$('#activitiesGrid td.control img.expandRow').live( 'click', function () {
var nTr = this.parentNode.parentNode;
var i = $.inArray( nTr, anOpen );
if ( i === -1 ) {
$(this).attr( 'src', sImageURL+"details_close.png" )
.attr('title', 'Collapse section');
var nDetailsRow = activitiesTable.fnOpen( nTr, fnFormatDetails(activitiesTable, nTr), 'details' );
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push( nTr );
}
else {
$(this).attr( 'src', sImageURL+"details_open.png" )
.attr('title', 'Expand section');
activitiesTable.fnClose( nTr );
anOpen.splice( i, 1 );
}
} );
function fnFormatDetails( activitiesTable, nTr )
{
var oData = activitiesTable.fnGetData( nTr );
var sOut =
''+
'';
if(oData.results !== '') {
sOut += 'Results:'+oData.results+''
}
sOut +=
'Note:'+oData.note+''+
''+
'';
return sOut;
}
[/code]
Thanks again!
Allan
BTW, I'm trying to arrange for the company I work for to purchase support (since you don't accept donations) for all of your help and to support your efforts with this awesome product.
Thanks again... and again!
[code]
var that = this;
$('#activitiesGrid tbody tr').each( function () {
var data = that.fnGetData( this );
for(var key in data) {
if ( data[key] === "Not Resulted" ) {
console.log('key: ' + key + '\n' + 'value: ' + data[key]);
activitiesTable.fnOpen( this );
}
}
});
[/code]
The output for console.log() is this:
LOG: key: resulted
value: Not Resulted
LOG: key: resulted
value: Not Resulted
Also fnOpen requires the data to display, which might be why it isn't working. That's my fault from the comment above - corrected now.
Allan
I'll be cleaning this up a bit to use a function call instead of the slideDown, etc in this block, but this is my fnDrawCallback currently just in case it helps anyone else out:
[code]
var that = this;
$('#activitiesGrid tbody tr').each( function () {
var data = that.fnGetData( this );
var nDetailsRow = '';
if(data !== null){
if ( data.resulted === "Not Resulted" ) {
nDetailsRow = activitiesTable.fnOpen( this, fnFormatDetails( activitiesTable, this ), 'details' );
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push( this );
}
}
});
[/code]
Thanks again for all your help!