Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined

Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined

protomeprotome Posts: 25Questions: 11Answers: 1

Hello
I have a problem in one of my pages, where I get this error in the console_log.
"Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined"

I have other pages that display all the datatable options without problem. But this one.
All pages have the same include files (but for the specific js file).
This is a very simple page, with 2 tabs and small tables. I have been comparing the code line by line with a page where it works, and cannot find any difference.
Could somebody hint me where the problem might be so I can find it ? what gives this error in most cases ?
Thanks for the help
pat

This question has an accepted answers - jump to answer

«1

Answers

  • protomeprotome Posts: 25Questions: 11Answers: 1
    Answer ✓

    SOLVED: this can help others.

    A simple mistake, the table header had a column "<th></th> with no title, but the column did not exist in the table itself. I could not see it missing (because o no title and no borders).

    Was helped by looking at the line in the datatable.js which gave the error - was implying a tr was at fault, so looked more carefully at my table and not my overall code

    Pat

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Thanks for posting back - good to hear you've got this sorted out!

    Allan

  • aravinthbabuaravinthbabu Posts: 1Questions: 0Answers: 0

    I'm also getting the same error. I checked the table headers. No issues up there.
    This issues occurs only when data is not available for the table.

    Do we have any other way to fix this issue ?

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin
    edited February 2016

    Can you link to a page showing the issue please.

  • bmcc81bmcc81 Posts: 2Questions: 1Answers: 0
    edited May 2016

    Hi,

    I seem to have the same issue:

    http://stackoverflow.com/questions/37080190/datatable-breaks-nested-repeater-and-bootstrap

    I only have 1 table showing, but use 2 repeaters...

    In the DOM my tables is formed properly, but says I have a non matching table elements...

    Please HELP!

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Happy to help - as requested in my post above, please link to a test page showing the issue so it can be debugged.

    Allan

  • ctumblesonctumbleson Posts: 1Questions: 0Answers: 0

    In a dataTable that has 0 entries, but has a column with no title or a title of just ( ). (For example a column for action buttons that has no title), this causes a JS error like in original report.

    This issue is immediately resolved once the amount of rows in table is greater than 0.

    Debug information - http://debug.datatables.net/amotez

    Rewriting logic to only show DataTable if entries are greater than 0 is the current workaround for me

  • mtindallmtindall Posts: 10Questions: 1Answers: 0

    For me the problem was that if i had no data, I was writing in my on row of colspan="# of headers" and so only 1 td for however many columns was causing the error. I removed this to find out datatables automatically provides a "no data in table row" for me!

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    A table with no title in a single column and no rows in the table, shouldn't be a problem.

    Allan

  • DecoyDecoy Posts: 1Questions: 0Answers: 0

    got same error because of number of columns in table not matching the "columns": declaration .
    "columns": [
    { "width": "1%" },
    { "width": "4%" },
    { "width": "30%" },
    { "width": "3%" },
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null
    ]
    the number of "columns" declaration must match number of columns in table

  • lastbytelastbyte Posts: 8Questions: 0Answers: 0

    The problem arises when you have a table with multiple header columns but a row in the tbody with a single <td> and a colspan set to the full width. See: http://live.datatables.net/rexixevu/60/edit

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    This is correct. DataTables currently doesn't support colspan or rowspan in the tbody.

    Allan

  • tgodfreytgodfrey Posts: 1Questions: 0Answers: 0

    FWIW, this same error occurs if you have a <thead> inside of a <tr>.

    I'm quite sure I have no idea why I might know this...

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Can you show us the HTML you are using? thead as an immediate child of tr isn't valid HTML.

    Allan

  • abshekvabshekv Posts: 1Questions: 0Answers: 0
    edited January 2017

    This error occurs if we specify a column index which is not valid for "aoColumnDefs", "aTargets".

    For Example,
    If you are working on a table with 6 columns and then if you specify the column properties like this - '"aoColumnDefs": [{ "bSortable": false, "aTargets": [0, 6] }]'

    Then we encounter the error in discussion, as our max column will be 5 and we have specified 6 for "aTargets".

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Yes - you will get an error if you attempt to address a column that doesn't exist.

    Allan

  • RozhRozh Posts: 1Questions: 0Answers: 0

    We had the same error, what fixed it for us is changing the (target) in the datatable initialization based on the number of columns starting from 0

    In our table we had 4 columns so taget: [3]

    $.extend( $.fn.dataTable.defaults, {
    columnDefs: [{
    targets: [ 3 ]
    }]
    });

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Yes, like the rest of Javascript, the columnDefs.targets option is zero indexed.

    Good to hear you have it working.

    Allan

  • DivyabharathiDivyabharathi Posts: 1Questions: 0Answers: 0

    I am getting this error, when I used colspan. Can anyone help me out for my issue?

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Are you using colspan in the tbody? If so, that isn't supported as discussed many times in this forum. Equally, if you are using it in the thead you need to still have a unique cell per column.

    We would need a test case, per the forum rules, to be able to help any further.

    Allan

  • MrFastMrFast Posts: 1Questions: 0Answers: 0

    "DataTables currently doesn't support colspan or rowspan in the tbody"

    Auch! That bit me :'( .
    Any plans for support of colspan?

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Not currently I'm afraid. Long term it would be nice, but I can't see it happening any time soon. It adds a lot of complication to things like filtering, sorting and column visibility.

    Allan

  • tsaomichaeltsaomichael Posts: 1Questions: 0Answers: 0
    edited July 2017

    datatables v1.10.15

    My console show this error =>
    jquery.dataTables.min.js:24 Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined at Ja (jquery.dataTables.min.js:24)

    sometimes show javascript error from datatables. How to fix, please?

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Post a link to a test case showing the issue and I'd be happy to look into it.

    Most likely you are using a rowspan or colspan in the tbody, or the columns array does not match the number of columns in the HTML.

    Allan

  • IdahoDixonIdahoDixon Posts: 3Questions: 0Answers: 0

    If it helps anyone ... when I was getting this error recently, it was NOT due to a mismatch between the number of <th></th> and <td></td> elements. It was caused by reference a non-existent column in my columnDefs, e.g.

            .ready(function () {
                $('#printLettersList').DataTable({
                    pageLength: 10,
                    paging: true,
                    searching: true,
                    order: [[0, "asc"]],
                    columnDefs: [{ orderable: false, targets: [7] }] // 6 was the highest index, not 7
                });
            });
    
  • DaveYoungDaveYoung Posts: 1Questions: 0Answers: 0

    I had this same thing and none of the ideas above fixed it for me. This one was a bit of head scratcher until I got it figured out.

    My table has only two columns and I'm using a <tr><td colspan="2"><td></tr> from time to time. The table is syntactically correct. I'm using the colspans to separate logical sections of data.

    The error comes from the fact that I'm using HTML5 data attributes on the <td> tags. Specifically the data-order attribute. In this case Datatabes does not support colspans on <td> tags.

    To get this to work properly for me I replaced the <td colspan="2"> tag with two <td> tags that included the data-order attributes. I used the same attribute value for the row coming next so that the order doesn't get wonky when the order is changed.

    Hope that helps someone!

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    Thanks for posting that information - I'm sure others will find it useful. I really need to improve the error reporting from DataTables for that sort of thing - sorry!

    You are absolutely correct - DataTables does not full support colspan. Each column must have its own unique header cell in the header. You can use a colspan in the header, but there would need to be another row which has a unique cell for each column (example).

    Allan

  • cintadewiameliacintadewiamelia Posts: 3Questions: 1Answers: 0

    Hello,
    I'm also getting the same error is "Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined". I checked the table headers. No issues up there.

    Do we have any other way to fix this issue ?
    Thanks for the help

  • allanallan Posts: 49,495Questions: 1Answers: 7,283 Site admin

    That error typically happens if columns and the HTML have a different number of columns defined, or the thead and tbody have a different number of columns defined in them. They all need to be the same.

    Other than that, we'd need a link to a test case showing the issue.

    Allan

  • cintadewiameliacintadewiamelia Posts: 3Questions: 1Answers: 0

    I have checked the number of columns in the table, and it is appropriate. But when I try to go to the table that does not have data, there is no error in console_log.

Sign In or Register to comment.