Adding extra line to table for Adsense code
Adding extra line to table for Adsense code
markjo
Posts: 66Questions: 0Answers: 0
I need to put Google Adsense code inside my table's center. (for example if table has 10 rows, I need to put after 5th row)
Because of Google TOS I will put code after document ready and won't update adsense code.
Regarding to this: http://www.datatables.net/forums/discussion/433/ajax-reload/p1
Best option seems like adding to "fnDrawCallback" function.
My tables has 10 columns. Regarding to previous topic I tried to put google code after 3rd row.
[code]"fnDrawCallback": function () {
var gnTr = document.createElement( 'tr' );
var nCell = document.createElement( 'td' );
nCell.colSpan = 0;
nCell.innerHTML = "google code";
gnTr.appendChild( nCell );
var nTrs = $('#mytable tbody tr');
nTrs[3].parentNode.insertBefore( gnTr, nTrs[3] );
}[/code]
But I got this error:
"Datatables warning (table id = 'mytable') : Requested unknown parameter '1' from the data source for row 3.
And my table didn't paginated.
1) How can I fix this?
2) Is there a better way for this situation since August 2009's discussion.
Thank you in advance.
Because of Google TOS I will put code after document ready and won't update adsense code.
Regarding to this: http://www.datatables.net/forums/discussion/433/ajax-reload/p1
Best option seems like adding to "fnDrawCallback" function.
My tables has 10 columns. Regarding to previous topic I tried to put google code after 3rd row.
[code]"fnDrawCallback": function () {
var gnTr = document.createElement( 'tr' );
var nCell = document.createElement( 'td' );
nCell.colSpan = 0;
nCell.innerHTML = "google code";
gnTr.appendChild( nCell );
var nTrs = $('#mytable tbody tr');
nTrs[3].parentNode.insertBefore( gnTr, nTrs[3] );
}[/code]
But I got this error:
"Datatables warning (table id = 'mytable') : Requested unknown parameter '1' from the data source for row 3.
And my table didn't paginated.
1) How can I fix this?
2) Is there a better way for this situation since August 2009's discussion.
Thank you in advance.
This discussion has been closed.
Replies
A link would be very useful.
Allan
I'm trying to add row to my table while initializing it, it is in table's constructor.
On document load I create table and I put "fnDrawCallback":updateTableFuncts(1), inside my table constructor. "updateTableFuncts" includes table related function and "addNewLine" function as well.
I need to call "addNewLine" function every time table is redrawed.
Although "unknown parameter" dialog, my code is inserted after the 3rd row successfully.
But I couldn't understand what did I di wrong for error dialog.
I put my table into debug page:
http://debug.datatables.net/ikagew
Thank you for interest
Allan
http://tiny.cc/wg5giw
"fnDrawCallback": updateTableFuncts(1),
[/code]
You are assigning the result of running that function to your fnDrawCallback, and you are not returning a function. So updateTableFuncts is running before you initialise the table, inserting a row, and thus DataTables gives you the error.
Just add a small anon function:
[code]
"fnDrawCallback": function () { updateTableFuncts(1) },
[/code]
Allan
Thank you Allan for your help and quick response about my problem! :)
I use the solution above. But it seems like I need to put adsense code inside table while constructing the table.
If I add Adsense code after [code]$(document).ready()[/code], ads doesn't appear right because DOM is already loaded. I need to put that javascript snippet while creating the datatable.
Is there such an approach?
Thank you very much
Allan
[code]echo '';
.....
if ($rowNo == 5) {
echo "";
echo 'google_ad_client = "ca-pub-12345"; /* my advertisement */ google_ad_slot = "12345"; google_ad_width = 728; google_ad_height = 90; ';
echo "";
}
....
...
echo '';[/code]
But when I run datatable code for the table I got this error:
[quote]"DataTables warning (table id='mytable'): Requested unknown parameter '0' from the data source for row 5[/quote]
Is it so?
Thank you
But other rows' columns are narrow, but Adsense image is far more wider. (For example column size changes from 50px to 728px)
So table becomes unreadable.
It seems like when I use colspan I can't use datatables, when I create each columns for Adsense code columns width corrupts :))
echo '';
.....
if ($rowNo == 5) {
echo "";
echo "";
echo "";
echo 'google_ad_client = "ca-pub-12345"; /* my advertisement */ google_ad_slot = "12345"; google_ad_width = 728; google_ad_height = 90; ';
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
....
...
echo '';
No absolutely not. DataTables does not support rowspan or colspan in the TBODY. You can inject elements into the table using the DOM after the data has been gathered by DataTables, which is the method proposed above with fnDrawCallback, but you absolutely cannot have rowspan or colspan in the TBODY when the table is initialised.
Allan
I think I need such a solution.
Let the size of tbody as 20 rows.
I need to put this code after 10th row while constructing tbody. And this will create 11th row.
Is it possible to datatables to disregard specific rows.
For example in this situation datatables will sort all rows except taking 11th row into consideration.
Is it possible to implement such solution with a plugin?
Thank you
Allan