Looking for a way to disable "Incorrect column count" alert

Looking for a way to disable "Incorrect column count" alert

JiminyJiminy Posts: 13Questions: 4Answers: 0

I posted this earlier but it seems to have disappeared - feel free to delete if it is a duplicate.

Link to test case:
https://live.datatables.net/jijefola/2/edit

Description of problem:

Hi all

TLDR; We don't really have the resources to find and fix all instances of this issue, so I'm really hoping there is a flag that we can set to disable the "Incorrect column count" alert.

Longer version: We have been using Datatables happily for many many years in our enormous and ancient application, and we are just in the process of upgrading Datatables from 1.10.25 to latest 1.13.6. Unfortunately we are seeing the "Incorrect column count" alert (introducd in 1.13.0 I understand) on a couple of particularly old pages where the HTML is not up to modern standards, but which we are VERY reluctant to touch. I should add that these pages were all working fine on 1.10.25 - it seems the issue is occurring when the table has no rows. Obviously you don't really need Datatables functionality when your table has no data, and it works great when there IS data in the table, so what we really want here is this alert to go away.

Our other concern is that there may be other pages in our huge application where this alert is going to start popping up. This code is ancient and works just fine for what it does, and we really don't want to have to go rewriting or debugging this issue.

What we are looking for is a flag or setting that we can enable to disable the alert.

thanks

Answers

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    Hi,

    DataTable.ext.errMode = 'none';
    

    will disable all the errors and warnings DataTables gives: https://live.datatables.net/jijefola/3/edit . However, since the error is ignored the Javascript then goes on to throw an error (which you can see on the console).

    The error message is there for a reason! I'd very strongly encourage you to use only correct HTML.

    it seems the issue is occurring when the table has no rows.

    The thing is that it does have a row - at least in the HTML. What you should do is just have an empty tbody or none, and let DataTables show the "no records" message (actually looking at your HTML in the example it doesn't have an explicit tbody, which DataTables expects.

    If your tables are generated through a central function, just drop that invalid "empty" (not empty) row.

    Allan

  • JiminyJiminy Posts: 13Questions: 4Answers: 0
    edited October 2023

    Thanks as always, Allan. The problem is that we're not using a central function here, these particular tables predate that. We really do not want to have to touch the code that generates those tables. And there are a lot of them.

    Of course I realise that our HTML is incorrect, but as I said in my post, the way you were doing it in 1.10.25 worked perfectly for us, so we regret this change. You could even argue this was a breaking change on your part, although of course I see it from your point of view.

    I'll try the suggested DataTable.ext.errMode = 'none'; I agree it's quite drastic though, it would be preferable to log a warning on the console

    I appreciate your time and response.

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    I thought there was a console option for the errMode, but apparently not - I need to look into that. However, there is a way to get it to log to console - with a custom function:

    DataTable.ext.errMode = function (s, tn, msg) {
     console.log(msg, tn);
    };
    

    https://live.datatables.net/jijefola/5/edit

    It still goes on to give a JS error at that point. Which was the case before with 1.10.25 anyway, which I'd expected - the error message basically gave a friendly way for devs to see the error and understand what it meant.

    I'd actually argue that this was a bug fix to let people know that their HTML is invalid. We used to get a lot of questions which boiled down to missing a th or td in the header or body. It didn't worked in 1.10.x either, since it is invalid HTML and DataTables has always required valid HTML (here be dragons ;)). It just didn't show the "helpful" message saying what to fix :)

    Allan

  • JiminyJiminy Posts: 13Questions: 4Answers: 0

    Yeah, that's a useful workaround. Actually, if I use DataTable.ext.errMode = 'throw'; it makes the least amount of console noise, so I might just go with that.

    I fully get your argument on whether it was a bug fix or a breaking change. Unfortunately those of us with ancient sprawling applications are really squeezed - on on hand we have pointy haired bosses demanding we keep up with security updates on 3rd party libraries like Datatables. And on the other hand, we have code that we really don't want to touch as there is zero benefit. The longer I can kick to touch having to go near that code, the easier my life is. If you can help me with that, I'd be very grateful, but of course I know it's not the "right way" that things should be done. Economic realities etc etc

    Have a good weekend and thanks for the solution.

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949
    edited October 2023

    If you are going to add DataTable.ext.errMode to your pages maybe it would be just as easy to write a reusable function that can be called to clear the tbody before you init Datatables.

    Kevin

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    That's an excellent idea Kevin! Count the header columns and the first row's columns. If no match then remove the body row and side step the error (and remove the JS error that you had in 1.10).

    Allan

  • JiminyJiminy Posts: 13Questions: 4Answers: 0

    Thanks Kevin and Allan. I am reluctant to alter the contents of tbody as there may be information there important to the user. Again the goal here is to just make the alert go away, without having to touch crufty old pages. I'm going to use the 'throw'.

    Thanks again.

Sign In or Register to comment.