无法读取属性aDataSort。 DataTable引导程序

时间:2016-09-20 09:12:56

标签: javascript jquery twitter-bootstrap asp.net-mvc-4

我刚开始了解bootstrap并创建一个可以向DataTable显示数据的简单项目,但我遇到此错误Cannot read property aDataSort of undefined

如果我弄错了,可以随意编辑我的代码

这些是我的代码

JS

var globalPersonId = 1;
var dataTablesOrderedList = "";
$(document).ready(function () {

    var dataTablesFirstBS = $('#dataTables-FIrstSample').DataTable({
        responsive: true,
        processing: true,
        info: true,
        search: true,
        sort: false,
        stateSave: true,
        order: [[1, "asc"], [2, "asc"]],
        lengthMenu: [[50, 100, 200, -1], [50, 100, 200, "All"]],
        ajax: { "url": "/BS/GetFirstDataTable" },
        columns:
        [
            { data: "BSId", title: "", visible: false, searchable: false, sortable: false },
            { data: "Name", title: "Name", sClass: "alignCenter", sortable: false }
        ]
    });

MyFirstBS();
    function MyFirstBS() {

        dataTablesOrderedList = $('#tblMyFirstBS').DataTable({
            responsive: true,
            processing: true,
            info: true,
            retrieve: true,
            destroy: true,
            search: true,
            sort: false,
            stateSave: true,
            lengthMenu: [[5, 10, 20, -1], [5, 10, 20, "All"]],
            ajax: {
                "url": "/BS/GetFirstDataTable",
                "data": function (d) {
                    d.BSId = globalPersonId;
                }
            },
            columns:
        [
            { data: "BSId", title: "", visible: false, searchable: false, sortable: false },
            { data: "Name", title: "Name",  searchable: false, sortable: false }
        ]
        });
    }


});

控制器

 public JsonResult GetFirstDataTable()
    {

        var Data = new List<object>();

        Data = db.FirstBS.Where(x => x.BSId == x.BSId)
        .Select(t =>
            new
            {
                BSId = t.BSId,
                Name = t.Name
            }).ToList<object>();
        return gf.DataTableAjaxHandlerClientSide(Data);
    }

1 个答案:

答案 0 :(得分:0)

我通过删除第二个订单来解决我的问题,这是我现在的新订单

order: [[1, "asc"]],