2017-12-18 110 views
1

无法设置属性“_DT_CellIndex”我有一个表,其中colspan导致上述error列跨度4的表给这个错误遗漏的类型错误:未定义

tabledynamic它可能会增长基础上data

我使用下面的CDN为datatable

//cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js

这里是演示:https://jsfiddle.net/3mazrcvL/10/

这里是我的表

<table class="table table-boardered" id="examples"> 
     <thead> 
      <tr> 
       <th>Customer Id</th> 
       <th>project_name</th> 
       <th>product_name</th> 
       <th>quantity</th> 
       <th>price</th> 
      </tr> 
     </thead> 
<tbody> 



    <tr class="sum"> 
     <td>9</td> 
     <td></td> 
     <td>first</td> 
     <td>1</td> 
     <td>90</td> 
    </tr> 


    <tr class="sum"> 
     <td>9</td> 
     <td></td> 
     <td>first</td> 
     <td>1</td> 
     <td>90</td> 
    </tr> 


    <tr class="sum"> 
     <td>9</td> 
     <td></td> 
     <td>second</td> 
     <td>7</td> 
     <td>3000</td> 
    </tr> 


    <tr class="sum"> 
     <td>9</td> 
     <td></td> 
     <td>second</td> 
     <td>7</td> 
     <td>3000</td> 
    </tr> 


    <tr class="sum"> 
     <td>11</td> 
     <td></td> 
     <td>pen</td> 
     <td>2</td> 
     <td>90</td> 
    </tr> 


    <tr class="sum"> 
     <td>11</td> 
     <td></td> 
     <td>pencil</td> 
     <td>2</td> 
     <td>90</td> 
    </tr> 

    <tr> 
<td colspan="4">Total</td> 
<td id="total">42540</td> 
</tr> 
</tbody> 
</table> 

js代码

$(document).ready(function() { 
     var table = $('#examples').DataTable(); 
     $('a.toggle-vis').on('click', function (e) { 
      e.preventDefault(); 

      var column = table.column($(this).attr('data-column')); 
      column.visible(!column.visible()); 
     }); 

     $('#examples tfoot th').each(function() { 
      var title = $('#examples thead th').eq($(this).index()).text(); 
      $(this).html('<input tyepe="text" placeholder="Search ' + title + '"/>'); 
     }); 
     table.columns().eq(0).each(function (colIdx) { 
      $('input', table.column(colIdx).footer()).on('keyup change', function() { 
       table 
         .column(colIdx) 
         .search(this.value) 
         .draw(); 
      }); 
     }); 

     $('#exportAttendance222').bind('click', function (e) { 

      $('#examples').tableExport({ type: 'excel', escape: 'false', bootstrap: true}); 
     }); 
    }); 

请帮我在此先感谢!

回答

2

方法1

当使用的数据表,使用列跨度= 4后,得到3- TD为显示无

<tr> 
    <td colspan="4">Total</td> 
    <td style='display:none'></td> 
    <td style='display:none'></td> 
    <td style='display:none'></td> 
    <td id="total">42540</td> 
</tr> 

实施例:https://jsfiddle.net/3mazrcvL/18/

方法2

是通过使用TFOOT

<tfoot> 
    <tr> 
     <td colspan="4">Total</td> 
     <td id="total">42540</td> 
    </tr> 
</tfoot> 

实施例:https://jsfiddle.net/3mazrcvL/17/

方法3

创建空白TFOOT和渲染TFOOT使用的数据表

HTML

<tfoot> 
    <tr> 
     <td colspan="4">Total</td> 
     <td id="total">0.00</td> 
    </tr> 
</tfoot> 

SCRIPT

var table = $('#examples').DataTable({ 
       "footerCallback": function (row, data, start, end, display) { 
        var api = this.api(), data; 
        // Remove the formatting to get integer data for summation 
        var intVal = function (i) { 
         return typeof i === 'string' ? 
           i.replace(/[$,]/g, '') * 1 : 
           typeof i === 'number' ? 
           i : 0; 
        }; 
        total = api.column(4).data().reduce(function (a, b) { 
          return intVal(a) + intVal(b); 
        }, 0); 
        $(api.column(4).footer()).html(total); 
       }, 
    }); 

实施例:https://jsfiddle.net/3mazrcvL/19/

+0

很好的解决方案!! – EaB

相关问题