rocky
rocky

Reputation: 339

Uncaught TypeError: Cannot read property 'className' of undefined dataTable

I have table:

HTML

<table id="mydata">
    <thead>
        <tr>
            <th>Data 1</th>
            <th>Data 2</th>
            <th>Data 3</th>
            <th>Data 4</th>
        </tr>
    </thead>
    <tbody>
        <tr class="main">
            <td class="data_1">A</td>
            <td class="data_2">B</td>
            <td class="data_3">C</td>
            <td class="data_4">D</td>
        </tr>
   </tbody>
</table>

When i'm using dataTable to sort with jquery:

JavaScript

jQuery('#mydata').dataTable({
    "sDom": " ",
    "bPaginate": false,
    "bInfo": false,
    'bFilter':false,                        
    "aoColumns": [
        null,               
        null,
        null,
        null
    ]
});

It's worked.

But, when i add child rows for main:

HTML

<table id="mydata">
    <thead>
        <tr>
            <th>Data 1</th>
            <th>Data 2</th>
            <th>Data 3</th>
            <th>Data 4</th>
        </tr>
    </thead>
    <tbody>
        <tr class="main">
            <td class="data_1">A</td>
            <td class="data_2">B</td>
            <td class="data_3">C</td>
            <td class="data_4">D</td>
        </tr>

        <tr class="detail-header">
            <td><strong>A1</strong></td>
            <td><strong>B1</strong></td>
            <td><strong>C1</strong></td>
            <td><strong>D1</strong></td>
        </tr>
        <tr class="detail">
            <td><strong>A2</strong></td>
            <td><strong>B2</strong></td>
            <td><strong>C2</strong></td>
            <td><strong>D2</strong></td>
        </tr>
        <tr class="control">
            <td colspan="2"><a href="#">Show details</a></td>
            <td colspan="2"><a href="#">Hide details</a></td>
        </tr>
    </tbody>
</table>

In that html: detail-header, detail and control are childs of main and they show when click to Show details, it's should ignore when sort but i seem they also sort by dataTable so i received error:

Uncaught TypeError: Cannot read property 'className' of undefined

Upvotes: 1

Views: 10668

Answers (1)

davidkonrad
davidkonrad

Reputation: 85518

dataTables does not accept colspans in <tbody>. Place the last row (the row with links) in a <tfoot> instead :

<tfoot>
    <tr class="control">
        <td colspan="2"><a href="#">Show details</a></td>
        <td colspan="2"><a href="#">Hide details</a></td>
    </tr>
</tfoot>  

demo -> http://jsfiddle.net/71zcn578/

Upvotes: 5

Related Questions