数据表不能在我的表在mvc查看页面上工作

问题描述:

我想使表作为datatable,但它不适用于我的表。 datatable在静态表中工作,但即时添加动态表时,它不显示任何数据表特性,如搜索选项和分页。所有记录即使在分页中选定10时也显示。数据表不能在我的表在mvc查看页面上工作

代码

<script> 
      $(document).ready(function() { 
       $('#example').DataTable(); 
      }); 
     </script> 


    <table id="example" class="display" width="100%" cellspacing="0"> 
    <thead> 
     <tr> 
      <th>deviceid</th> 
      <th>status</th> 
      <th>UpdatedTime</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>deviceid</th> 
      <th>status</th> 
      <th>UpdatedTime</th> 
     </tr> 
    </tfoot> 

@foreach (var item in Model) 
{ 
    <tbody> 
     <tr> 
      <td>@Html.DisplayFor(modelItem => item.deviceid)</td> 
      <td>@Html.DisplayFor(modelItem => item.status)</td> 
      <td>@Html.DisplayFor(modelItem => item.UpdatedTime)</td> 
     </tr> 
    </tbody> 
} 
</table> 
+0

我已经提到datatable.while的JS和CSS文件的一些内容替换静态表显示其确定年代,但不与动态table.console无差错类型错误的工作:未定义C –

+0

我检查。在我的代码中,我已经关闭了表格标签。我的问题是表是显示所有的记录,而不是按照分页下拉值显示记录,搜索选项也不起作用。我认为可能需要更改@foreach循环。 –

添加以下所有

//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css 
//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js 
//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js 
//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js 

实例链接https://jsfiddle.net/r8gd2227/3/

试试这个:

$(document).ready(function() { 
      $('#example').DataTable(); 
     }); 
+0

即时消息我真正的代码我用表的正确的ID。我用id更新了我的问题。仍然不工作。 –

<table id="example" class="display" width="100%" cellspacing="0"> 
    <thead> 
     <tr> 
      <th>deviceid</th> 
      <th>status</th> 
      <th>UpdatedTime</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>deviceid</th> 
      <th>status</th> 
      <th>UpdatedTime</th> 
     </tr> 
    </tfoot> 

    <tbody> 
@foreach (var item in Model) 
{ 
     <tr > 
      <td>@Html.DisplayFor(modelItem => item.deviceid)</td> 
      <td>@Html.DisplayFor(modelItem => item.status)</td> 
      <td>@Html.DisplayFor(modelItem => item.UpdatedTime)</td> 
     </tr> 
} 
    </tbody> 
</table>