different columns number

different columns number

giorggiorg Posts: 4Questions: 1Answers: 0

Hi,
in my table I need something like this:

<tr>
<th>col 1</th><th>col 2</th>
</tr>
<tr><td colspan="2">subheader</td></tr>
<tr><td>val 1</td><td>val 2</td></tr>

if I remove the subheader row everything works like a charm, but if I leave it I get this error in console:

nTd is undefined

how to solve this?
thanks a lot

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    That doesn't look like valid HTML. You need to have thead and tbody tags. It should look more like this:

    <thead>
    <tr>
    <th>col 1</th><th>col 2</th>
    </tr>
    <tr><td colspan="2">subheader</td></tr>
    </thead>
    
    <tbody>
    <tr><td>val 1</td><td>val 2</td></tr>
    </tbody>
    

    Datatables doesn't support colspan within the body of the table. It is supported in the header though. Which is probably why you are getting the error. Here is an example:
    https://datatables.net/examples/basic_init/complex_header.html

    click on the HTML tab to see how this is setup.

    Kevin

  • giorggiorg Posts: 4Questions: 1Answers: 0

    hi,
    thanks for your answer, ofc that was only a part of the table, it is correctly formatted. Unfortunately looks like I cannot use datatables in this particular table, because the body has to be as I mentioned...

    thanks

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @giorg ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.