i am getting this error

i am getting this error

umaeswaraumaeswara Posts: 83Questions: 16Answers: 0

DataTables warning: table id=DataTables_Table_0 - Incorrect column count. For more information about this error, please see https://datatables.net/tn/18
can you please suggest, the remedy.
thanks,
Uma-

Answers

  • umaeswaraumaeswara Posts: 83Questions: 16Answers: 0

    i dont have any header in my table.
    here is the table
    Unnamed: 0 439
    company One1
    Price 436.23
    Change% 4.34

  • umaeswaraumaeswara Posts: 83Questions: 16Answers: 0

    if I want to add table header using my js file, but this js file is used by many other tables.
    how to check table which doesnt have deader and add an invisible table header. i was thinking columnDerfs with visible false, and th cells as first row. is that possible, if so how?

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited December 17

    The columns.title option can be used to create table headers but hey won't be hidden. However you could use CSS to hide them.

    You can create them in HTML and use something like style="display: none;" or better CSS to hide the th.

    Or you can use Javascript to jQuery methods to add the headers to the table before initializing Datatables. Use Stack Overflow to find the method that works for your situation.

    i was thinking columnDerfs with visible false,

    This will hide the whole column not just the header.

    Kevin

  • umaeswaraumaeswara Posts: 83Questions: 16Answers: 0

    Ok, thanks. I used java method to append header cells.
    if ($("table thead").length === 0) { ... } if anyone interested to solve similar problem.

    BTW, for the question if JS is common for all the tables which are in different pages.
    var table = $("table").DataTable({ ..... });
    inside this can I check table id etc? table data conditions to set some columnDefs ?

    thanks,
    Uma-

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    inside this can I check table id etc? table data conditions to set some columnDefs ?

    Inside the configuration object no. Outside yes. Here is one way of doing it:

    $('table').each(function () {
      let options = {
        // defaults
        scrollX: true
      };
    
      // Table overrides
      if (this.id === 'myTable') {
        options.scrollX = false;
      }
      else if (this.id === 'thatTable') {
        // ...
      }
    
      $(this).DataTable(options);
    });
    

    Allan

  • umaeswaraumaeswara Posts: 83Questions: 16Answers: 0

    thanks, let me try and come back. I have several tables and each have different kind of options.

Sign In or Register to comment.