admin管理员组

文章数量:1026989

I just start to learn about bootstrap and creating a simple project that can show a data into DataTable but I am having this error Cannot read property aDataSort of undefined

Feel Free to edit my code if i got it wrong

These are my code

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 }
        ]
        });
    }


});

Controller

 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);
    }

I just start to learn about bootstrap and creating a simple project that can show a data into DataTable but I am having this error Cannot read property aDataSort of undefined

Feel Free to edit my code if i got it wrong

These are my code

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 }
        ]
        });
    }


});

Controller

 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);
    }
Share Improve this question edited Sep 20, 2016 at 9:30 KiRa asked Sep 20, 2016 at 9:12 KiRaKiRa 9243 gold badges19 silver badges46 bronze badges 7
  • i think you need to set sortable: false for all the columns defined under #tblMyFirstBS DataTable. Please try that and let me know. – vijayP Commented Sep 20, 2016 at 9:17
  • @vijayP i set it in dataTablesFirstBS columns I also set it in my function?. – KiRa Commented Sep 20, 2016 at 9:18
  • i don't see it in function MyFirstBS(). Can you please modify your question. – vijayP Commented Sep 20, 2016 at 9:20
  • @vijayP sorry typo. Do I need to set in my function? – KiRa Commented Sep 20, 2016 at 9:25
  • yes. Also from where you are calling this ` MyFirstBS()`? – vijayP Commented Sep 20, 2016 at 9:27
 |  Show 2 more ments

2 Answers 2

Reset to default 1

i solved that problem in my case by removing the order line

order: [[ 7, "desc" ]],

I solve my problem by removing the second order here is my new order now

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

I just start to learn about bootstrap and creating a simple project that can show a data into DataTable but I am having this error Cannot read property aDataSort of undefined

Feel Free to edit my code if i got it wrong

These are my code

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 }
        ]
        });
    }


});

Controller

 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);
    }

I just start to learn about bootstrap and creating a simple project that can show a data into DataTable but I am having this error Cannot read property aDataSort of undefined

Feel Free to edit my code if i got it wrong

These are my code

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 }
        ]
        });
    }


});

Controller

 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);
    }
Share Improve this question edited Sep 20, 2016 at 9:30 KiRa asked Sep 20, 2016 at 9:12 KiRaKiRa 9243 gold badges19 silver badges46 bronze badges 7
  • i think you need to set sortable: false for all the columns defined under #tblMyFirstBS DataTable. Please try that and let me know. – vijayP Commented Sep 20, 2016 at 9:17
  • @vijayP i set it in dataTablesFirstBS columns I also set it in my function?. – KiRa Commented Sep 20, 2016 at 9:18
  • i don't see it in function MyFirstBS(). Can you please modify your question. – vijayP Commented Sep 20, 2016 at 9:20
  • @vijayP sorry typo. Do I need to set in my function? – KiRa Commented Sep 20, 2016 at 9:25
  • yes. Also from where you are calling this ` MyFirstBS()`? – vijayP Commented Sep 20, 2016 at 9:27
 |  Show 2 more ments

2 Answers 2

Reset to default 1

i solved that problem in my case by removing the order line

order: [[ 7, "desc" ]],

I solve my problem by removing the second order here is my new order now

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

本文标签: javascriptCannot read property aDataSortDataTable bootstrapStack Overflow