Datatable creates two tables in scrollY mode
Datatable creates two tables in scrollY mode
Hi all,
When datatable is used in scrollY mode it actually creates two DOM tables - one for the content and one for the header to make it detached from scrolling.
I create datatable dynamically with the code like that:
var $table = $("").appendTo($container);
$table.addClass(UIClasses.Table);
then initialize datatable here:
var oTable = $table.dataTable(cur_data);
Later I would identify the created table by jQuery select using UIClasses.Table class:
var $table = $("." + UIClasses.Table, $container);
That seems quite simple, however, in scrollY mode datatable creates another DOM table element for the table header and it seems that it copies class from the main table to the header. As such, when I query for the table node using jQuery: $("." + UIClasses.Table, $container); I receive two elements as the result.
My question is:
How can I distinguish between the two and find the reference to the main table?
P.S.
Currently I am using a workaround, which I would like to remove in favor of a better way :
//todo: hack: skipping the header;
if (this.$table.length > 1)
this.$table = $(this.$table[this.$table.length-1]);
When datatable is used in scrollY mode it actually creates two DOM tables - one for the content and one for the header to make it detached from scrolling.
I create datatable dynamically with the code like that:
var $table = $("").appendTo($container);
$table.addClass(UIClasses.Table);
then initialize datatable here:
var oTable = $table.dataTable(cur_data);
Later I would identify the created table by jQuery select using UIClasses.Table class:
var $table = $("." + UIClasses.Table, $container);
That seems quite simple, however, in scrollY mode datatable creates another DOM table element for the table header and it seems that it copies class from the main table to the header. As such, when I query for the table node using jQuery: $("." + UIClasses.Table, $container); I receive two elements as the result.
My question is:
How can I distinguish between the two and find the reference to the main table?
P.S.
Currently I am using a workaround, which I would like to remove in favor of a better way :
//todo: hack: skipping the header;
if (this.$table.length > 1)
this.$table = $(this.$table[this.$table.length-1]);
This discussion has been closed.
Replies
unless jquery is adding thead and tbody tags for you, this is not supported.
What about tfoot ?
add the thead and tbody, see if that helps at all.. ?