Method Column() not works for DataTable with javascript source ,another way to hide and show coumns?

Method Column() not works for DataTable with javascript source ,another way to hide and show coumns?

pipo75pipo75 Posts: 14Questions: 7Answers: 0
edited February 2015 in Free community support

Methods like Column("0") , Column("1").visible(false) ...
work with DataTable with data html source like that

    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
</tbody>

</table>

table = $('#example').DataTable();
var col = table.column("0").visible(false);

But it does not works and launch an error with DataTable with javascript source like that:

table = $('#example').dataTable({
"data": source,
"columns": columns,
"columnDefs": defs
});
table = $('#example').DataTable();
var col = table.column("0").visible(false);

Is exist anotherway to hide or show columns?

This question has an accepted answers - jump to answer

Answers

  • pipo75pipo75 Posts: 14Questions: 7Answers: 0

    I finally found, we can do like that:

    table.fnSetColumnVis(3, false);

    I don't understand why it is working with that function and no wwith column()but it works!

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Answer ✓

    $('#example').dataTable

    It doesn't work with that because you are using dataTable rather than DataTable. See the second top FAQ :-)

    Allan

  • pipo75pipo75 Posts: 14Questions: 7Answers: 0

    thank!!!

This discussion has been closed.