Dynamic column in jQuery DataTables <p>In my application there are some columns that were given privileges. If the column is not given the right to access that particular column is not shown.</p> <p>My code is like this : <a href="http://jsfiddle.net/oscar11/5jccbzdy/11/" rel="nofollow">http://jsfiddle.net/oscar11/5jccbzdy/11/</a></p> <pre><code>// DataTable var table = $('#example').DataTable({ "order": [[0, 'asc']], "drawCallback": function (settings){ var api = this.api(); // Zero-based index of the column containing names var col_name = 0; // If ordered by column containing names if (api.order()[0][0] === col_name) { var rows = api.rows({ page: 'current' }).nodes(); var group_last = null; api.column(col_name, { page: 'current' }).data().each(function (name, index){ var group = name; var data = api.row(rows[index]).data(); if (group_last !== group) { $(rows[index]).before( '&lt;tr class="group" style="background-color:' + data[4] + '"&gt;&lt;td colspan="5"&gt;' + group + '&lt;/td&gt;&lt;/tr&gt;' ); group_last = group; } }); } } }); </code></pre> <p>How to make the above code becomes more dynamic and adjusting the number of columns that are given privileges?</p> <p>If the number of columns that were given privileges: 5, then:</p> <pre><code>'&lt;tr class="group" style="background-color:' + data[4] + '"&gt;&lt;td colspan="5"&gt;' + group + '&lt;/td&gt;&lt;/tr&gt;' </code></pre> <p>If the number of columns that were given privileges: 3, then:</p> <pre><code> '&lt;tr class="group" style="background-color:' + data[2] + '"&gt;&lt;td colspan="3"&gt;' + group + '&lt;/td&gt;&lt;/tr&gt;' </code></pre> <p>Thank you</p>