Hello to all,
I try to use fnFooterCallback in order to calculate the sum of some columns. It is ok and pretty cool! But unfortunalty, my Javascript fails when I want to add the ColVis function on my table.
My HTML:
My JS:
Problem starts when I try to hide or show columns, with this kind of messages:
TypeError: nCells[5] is undefined
nCells[5].innerHTML = arraytotaux[5];
Could you please help?
Thanks.
Regards.
Kyvu
I try to use fnFooterCallback in order to calculate the sum of some columns. It is ok and pretty cool! But unfortunalty, my Javascript fails when I want to add the ColVis function on my table.
My HTML:
<table id="mydatatable"> <thead> <tr><th>Part number</th><th>Desc 1</th><th>Desc 2</th><th>Quantity</th><th>Weight</th><th>Height</th><th>Misc</th></tr> </thead> <tbody> <tr><td>201-1704</td><td>desc 1</td><td>desc 2</td><td>1</td><td>6</td><td>14</td><td>misc</td></tr> <tr><td>6Y-4898</td><td>desc 1</td><td>desc 2</td><td>2</td><td>1</td><td>6</td><td>misc</td></tr> <tr><td>6Y-5685</td><td>desc 1</td><td>desc 2</td><td>3</td><td>2</td><td>11</td><td>misc</td></tr> <tr><td>4I-7472</td><td>desc 1</td><td>desc 2</td><td>4</td><td>6</td><td>12</td><td>misc</td></tr> <tr><td>124-3296</td><td>desc 1</td><td>desc 2</td><td>5</td><td>6</td><td>13</td><td>misc</td></tr> <tr><td>141-9655</td><td>desc 1</td><td>desc 2</td><td>6</td><td>2</td><td>14</td><td>misc</td></tr> <tr><td>166-3729</td><td>desc 1</td><td>desc 2</td><td>7</td><td>3</td><td>6</td><td>misc</td></tr> <tr><td>207-3658</td><td>desc 1</td><td>desc 2</td><td>8</td><td>6</td><td>6</td><td>misc</td></tr> <tr><td>255-8095</td><td>desc 1</td><td>desc 2</td><td>9</td><td>6</td><td>4</td><td>misc</td></tr> <tr><td>125-4403</td><td>desc 1</td><td>desc 2</td><td>10</td><td>3</td><td>4</td><td>misc</td></tr> </tbody> <tfoot> <tr><th>Total</th><th></th><th></th><th></th><th></th><th></th><th></th></tr> </tfoot> </table>
My JS:
$("#mydatatable").dataTable({ "aaSorting": [], "bSort": true, "bPaginate": true, "bAutoWidth": false, "sDom": 'C<"clear">lfrtip', "oColVis": {"buttonText": "Hide", "aiExclude": [0, 1, 2]}, "fnFooterCallback": function(nRow, aaData, iStart, iEnd, aiDisplay) { var arraytotaux = []; arraytotaux[3] = 0; arraytotaux[4] = 0; arraytotaux[5] = 0; for (var i = 0; i < aiDisplay.length; i++) { arraytotaux[3] += aaData[aiDisplay[i]][3] * 1; arraytotaux[4] += aaData[aiDisplay[i]][4] * 1; arraytotaux[5] += aaData[aiDisplay[i]][5] * 1; } var nCells = nRow.getElementsByTagName("th"); nCells[3].innerHTML = arraytotaux[3]; nCells[4].innerHTML = arraytotaux[4]; nCells[5].innerHTML = arraytotaux[5]; } })
Problem starts when I try to hide or show columns, with this kind of messages:
TypeError: nCells[5] is undefined
nCells[5].innerHTML = arraytotaux[5];
Could you please help?
Thanks.
Regards.
Kyvu