unable to locate _fnGetDataTablesData. Where should I place _fnGetDataTablesData code.
unable to locate _fnGetDataTablesData. Where should I place _fnGetDataTablesData code.
P4nk4j Sh4rm4
Posts: 25Questions: 7Answers: 0
/* ----- BEGIN added Code ----- */
"_fnGetHeaders": function() {
var dt = this.s.dt;
var thRows = dt.nTHead.rows;
var numRows = thRows.length;
var matrix = [];
// Iterate over each row of the header and add information to matrix.
for ( var rowIdx = 0; rowIdx < numRows; rowIdx++ ) {
var $row = $(thRows[rowIdx]);
// Iterate over actual columns specified in this row.
var $ths = $row.children("th");
for ( var colIdx = 0; colIdx < $ths.length; colIdx++ )
{
var $th = $($ths.get(colIdx));
var colspan = $th.attr("colspan") || 1;
var rowspan = $th.attr("rowspan") || 1;
var colCount = 0;
// ----- add this cell's title to the matrix
if (matrix[rowIdx] === undefined) {
matrix[rowIdx] = []; // create array for this row
}
// find 1st empty cell
for ( var j = 0; j < (matrix[rowIdx]).length; j++, colCount++ ) {
if ( matrix[rowIdx][j] === "PLACEHOLDER" ) {
break;
}
}
var myColCount = colCount;
matrix[rowIdx][colCount++] = $th.text();
// ----- If title cell has colspan, add empty titles for extra cell width.
for ( var j = 1; j < colspan; j++ ) {
matrix[rowIdx][colCount++] = "";
}
// ----- If title cell has rowspan, add empty titles for extra cell height.
for ( var i = 1; i < rowspan; i++ ) {
var thisRow = rowIdx+i;
if ( matrix[thisRow] === undefined ) {
matrix[thisRow] = [];
}
// First add placeholder text for any previous columns.
for ( var j = (matrix[thisRow]).length; j < myColCount; j++ ) {
matrix[thisRow][j] = "PLACEHOLDER";
}
for ( var j = 0; j < colspan; j++ ) { // and empty for my columns
matrix[thisRow][myColCount+j] = "";
}
}
}
}
return matrix;
},
/* ----- END added Code ----- */
Modified the following section of "_fnGetDataTablesData":
if ( oConfig.bHeader )
{
/* ----- BEGIN changed Code ----- */
var headerMatrix = this._fnGetHeaders();
for ( var rowIdx = 0; rowIdx < headerMatrix.length; rowIdx++ ) {
aRow = [];
for ( var colIdx = 0; colIdx < (headerMatrix[rowIdx]).length; colIdx++ ) {
sLoopData = headerMatrix[rowIdx][colIdx].replace(/\n/g," ").replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
sLoopData = this._fnHtmlDecode( sLoopData );
aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
}
aData.push( aRow.join(oConfig.sFieldSeperator) );
}
/* ----- END changed Code ----- */
}
Please help me.
This discussion has been closed.
Answers
I'm not clear on what you are attempting to do here. Could you clarify that please? Why do you need to modify the DataTables code here?
Allan
I found the above code in the forum blog, where the question was raised regarding exporting multiple table headers in excel and pdf. So I want to know where the code should be placed so that excel exports multiple headers in the output.
Pankaj sharma
I think that's for the legacy TableTools plug-in which is no longer supported.
I'm afraid there is currently no supported way to export multiple row header tables.
Allan
Is there any possibility of appending table row manually when exported to excel and how to apply the merge cell method. Any alternate solution will be much appreciated.
One more question, don't know whether Its right thing to ask here. Can you please explain me the below code line by line? What happens in each line??
var mergeCells = function ( row, colspan ) {
var mergeCells = $('mergeCells', rels);
mergeCells[0].appendChild( _createNode( rels, 'mergeCell', {
attr: {
ref: 'A'+row+':'+createCellPos(colspan)+row
}
} ) );
mergeCells.attr( 'count', mergeCells.attr( 'count' )+1 );
$('row:eq('+(row-1)+') c', rels).attr( 's', '51' ); // centre
};
Pankaj Sharma