How to change feature values after DataTable is already initialized?

How to change feature values after DataTable is already initialized?

kenxukenxu Posts: 9Questions: 0Answers: 0
edited October 2010 in General
Hello,

I initialized a DataTable to be scrollable. This table has to fit into its container. It is hard to determine the value for "sScrollY" upfront. It should equal to container's height minus table header's height. I know container's height but don't know table header's height until they are rendered. So I need to calculate and change "sScrollY" value after DataTable is initialized. How do I change this value?

Here is my code to initialize DataTable. As you can see "sScrollY" is set to 200. It should be set again later.
[code]
var $dataTable = $(".search-result-table", $container).dataTable(
{
"bJQueryUI" : true,
"sScrollY" : 200,
"sScrollX" : "100%",
"bPaginate" : false,
"bFilter" : false,
"bSort" : false,
"bSortClasses" : false,
"bInfo" : false,
"sDom" : '<"result-list"t>',
"aoColumnDefs" : aoColumnDefs
});
[/code]

Thank you in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Generally speaking you can't change the features after initialisation - although with the sScrollY parameter, it is possible to get around this. First you need to set the internally cached variable: oTable.fnSettings().oScroll.sX = whatever;, and then set the height of the element on the page yourself: $('div.dataTables_scrollBody').height( whatever ); - you will need to refine the selector if you have more than one table.

    This could be wrapped up into an API plug-in to make it slightly easier... :-)

    Allan
  • kenxukenxu Posts: 9Questions: 0Answers: 0
    Hi, Allan,

    If I only want to set sScrollY, can I skip sX? Thanks.

    Ken
  • kenxukenxu Posts: 9Questions: 0Answers: 0
    Hi, Allan,

    I think I found the answer myself. It is OK to only set the height and keep the initial sX. Thank you for your help.

    Ken
This discussion has been closed.