Ludus H Ludus H - 3 months ago 12x
jQuery Question

DataTables: how to put variable in table initialization code

I found that DataTables plug-in is very handsome and practical until you know at code start all necessary parameters. But, in my case I wish to change parameter scrollX according to detected document' height (60% of available height). I understand that here we talk about some kind of object but push and other tricks doesn't help. Here is problematic code:

$(document).ready(function() {
table = $('#example').DataTable( {
language: {
info: "Show _START_ til _END_ of _TOTAL_ recs" },
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false,
rowReorder: false,
ordering: false,
fixedColumns: {
leftColumns: 2,

and instead "300px" I planned to put some kind of Javascript variable that contain document height, but classic object manipulation doesn't show result. So, I tried to check:


but got error. Then tried to make table as public var but then got undefined value. Also:

table.push({'scrollX': '300px'});

and some weird combination, but nop. Any suggestion, please? Thanks.


Something like

$(document).ready(function() {
  var myScrollY = '300px';
  var table = $("#example").DataTable({
    scrollY: myScrollY