Datatables won't recognise more columns than 4

Datatables won't recognise more columns than 4

ArtuvazroArtuvazro Posts: 11Questions: 5Answers: 0
edited January 2016 in Free community support

I have encountered an issue while using datatables in a new web site. For some reason, I can only add 4 columns and if I try to add one more the table breaks. If you loook at the at the webpage (link provided), you'll see that the fifth column doesn't even have the arrows, it seems that datatables is ignoring the whole column.

I'm using datatables with this server side code: http://datatables.net/development/server-side/php_mysql

How it looks like with 4 columns:
http://i.imgur.com/yekYJmT.png

How it looks like with more than 4 columns:
See it live here:
http://localizacomopuedas.es/2.0/

I've tried many things but I can't seem to find a solution to this... With the database empty of data the issue persists. I've tried changing the column order in the array but nothing changes.

The thing is that I'm using more or less the same code in another site and I don't have this problem there.

Debug: http://debug.datatables.net/uroset

The query is ok because here I can see all the columns queried, even the one which is missing:
http://localizacomopuedas.es/2.0/newdt.php

This question has an accepted answers - jump to answer

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49
    edited January 2016 Answer ✓

    You added a new column to the HTML makeup, but not to your DataTables config.

    --- old ---
    "aoColumns": [
    null,
    { "sClass": "titleColumn" },
    null,
    null
    ],

    --- new ---
    "aoColumns": [
    null,
    { "sClass": "titleColumn" },
    null,
    null,
    null
    ],

    This is why it doesn't recognize your column. When adding a new column, there are 3 things you have to do:

    1. Add appropriate <th>

    2. Add to "columnDefs" or "columns", if applicable

    3. Add value to array being added to datatable

      -- in your case, it should be a 5 index array instead of 4

  • ArtuvazroArtuvazro Posts: 11Questions: 5Answers: 0

    Oh my god, thank you very much. I've completely forgotten about that. :/ Thank you!

This discussion has been closed.