Data columns don't resize with json

Data columns don't resize with json

allthestairsallthestairs Posts: 2Questions: 0Answers: 0
edited April 2012 in General
I am using a very slightly modified version of the http://datatables.net/development/server-side/django tutorial. I have my page working perfectly using Django templates to make a normal html table, it looks excellent. When I switch to server-side data and processing, using the exact methods in that repo, the columns stop resizing to fit their content. I have the exact same 5 columns with the same data in them. The only difference in my template/javascript is I add
[code]
"sAjaxSource": "{% url get_protein_list %}",
"bServerSide": true,
[/code]

to my $('#main').dataTable() function, and remove the part of the template that generates my ... section.

http://debug.datatables.net/ahofil - Server-side
http://debug.datatables.net/oramac - Normal

Replies

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    The most likely reason for this is that when the column widths are calculated, when server-side processing is enabled, DataTables doesn't have the data on the client-side, and thus can't take it into account. So what you can do is add:

    [code]
    fnInitComplete: function () {
    this.fnAdjustColumnSizing();
    }
    [/code]

    to your DataTables initialisation, which will do a column resize when the JSON has loaded for the first time. If you want it to adjust one every draw, use fnDrawCallback.

    Allan
  • allthestairsallthestairs Posts: 2Questions: 0Answers: 0
    This was perfect. I've been messing around with a limited knowledge of how Datatables (hell, Javascript) actually work, but this prompted me to check out callbacks. Thanks a lot!
This discussion has been closed.