一页上多个表的数据表各有不同的 td 计数

Datatables for mutiple tables on one page having different td count each

正在使用 id 在每个 table 上应用数据table,但它只触发一个 table 并在控制台中给出错误。 "Uncaught TypeError: Cannot set property 'nTf' of undefined" 而我需要在每个 table 上显示它。 无法应用 class,因为每个 table 都有不同的 td 计数。

例如,我有两个 tables,id 为 table1 和 table2,并将 datatable 调用为

$('#table1').DataTable(); $('#table2').DataTable();

如有任何帮助,请告知我们将不胜感激

我的第一个 table 是

<table id="table1">
  <thead> 
     <tr>
       <th>No.s</th>
       <th>Title</th>
       <th>project</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>test</td>
      <td>test project</td>
    </tr>
   </tbody>
   <tfoot>
     <tr>
       <th colspan="3"></th>
     </tr>
  </tfoot>
</table>

我的第二个 table 是

<table id="table2">
      <thead> 
         <tr>
           <th>No.s</th>
           <th>Title</th>
           <th>Task</th>
           <th>Actions</th>
        </tr> 
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>test</td>
          <td>test task</td>
          <td>Edit</td>
        </tr>
       </tbody>
       <tfoot>
         <tr>
           <th colspan="4"></th>
         </tr>
      </tfoot>
 </table>

Using class cannot be applied because each table has different td's count

无事可做when we use datatable for mutiple tables it works only for the tables which have same count of td's and can be applied using the both table's same class
Live Demo

我刚遇到这个问题,结果是脚上的 tds 太多了。检查您的行和列是否有额外内容、未关闭的标签等。