未捕获的TypeError:无法设置未定义的属性'_DT_CellIndex'

时间:2018-03-07 14:08:42

标签: javascript jquery asp.net-mvc asp.net-core

以下是我DataTable的内容。我正在尝试添加pagingsearching功能。但是,在检查时,我收到以下错误:

  

未捕获的TypeError:无法设置未定义的属性'_DT_CellIndex'

我的.cshtml代码如下:

<thead>
    <tr>
        <th data-column-id="Id" data-type="int" data-identifier="true" hidden>ID</th>
        <th data-column-id="DeviceName">Name</th>
        <th data-column-id="DeviceType">Device Type</th>
        <th data-column-id="DeviceManufacturer">Manufacturer Name</th>
        <th data-column-id="ModelNumber">Model</th>
        <th data-column-id="DateOfPurchase">Date of Purchase</th>
        <th data-column-id="Commands">Commands</th>
    </tr>
</thead>

我的jQuery代码如下:

 $(document).ready(function () {
        LoadPaging();
        $('#data-table-basic').removeClass("dataTable no-footer");
        //$('table.dataTable').addClass("table table-striped table-vmiddle");
    });

    function LoadPaging() {
        if(@count!= 0)
        {
            var table = $('#data-table-basic').DataTable({
                "pagination": true,
                "bSortable": false,
                "ordering": false,
                "searching": true,
                "bLengthChange": true,
                "info": true,
                //"lengthMenu": [6, 40, 60, 80, 100],
                "lengthMenu":[ [10, 20, 40, 60,80,100, -1], [10, 20, 40, 60,80,100, "All"] ],
                "pageLength": 10,
                language: {
                    paginate: {
                        next: '',
                        previous: ''
                    }
                }
            });
        }
    }

输出View上未显示搜索和分页功能。

1 个答案:

答案 0 :(得分:0)

由于Commands中没有model列,我不能在这里提及。移除<th data-column-id="Commands">Commands</th>后,我能够在paging上看到searchingView功能。

以下链接帮助我弄清楚出了什么问题: DataTables.net