0

Problem Description:

According to DataTables reference: https://datatables.net/examples/ajax/objects.html it should source data from my server and load it into the table but for some reason it's not recognizing the format of the json object sent by MVC 5

Error

"DataTables warning: table id=parentTable - Requested unknown parameter '0' for row 0, column 0.

Javascript

<script>
    $(document).ready(function () {
        $('#parentTable').DataTable(
                            {
                                'fixedHeader': true,
                                'ajax': '@Url.Action("GetView","Controller")',

                                'columns' : [

                                    { 'data': 'Column1', 'autoWidth': true },
                                    { 'data': 'Column2', 'autoWidth': true },
                                    { 'data': 'Column3', 'autoWidth': true },
                                    { 'data': 'Column4', 'autoWidth': true },
                                    { 'data': 'Column5', 'autoWidth': true },
                                    { 'data': 'Column6', 'autoWidth': true },
                                    { 'data': 'Column7', 'autoWidth': true },
                                    { 'data': 'Column8', 'autoWidth': true },
                                    { 'data': 'Column9', 'autoWidth': true },
                                    { 'data': 'Column10', 'autoWidth': true },
                                    { 'data': 'Column11', 'autoWidth': true },
                                    { 'data': 'Column12', 'autoWidth': true },
                                    { 'data': 'Column13', 'autoWidth': true },
                                    { 'data': 'Column14', 'autoWidth': true },
                                    { 'data': 'Column15', 'autoWidth': true }


                                ],
                                'order': [[1, 'desc']],
                                'aoColumns': [
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null,
                                    null
                                ]







                            });

    });
</script>

MVC 5 Action

public ActionResult GetView()
        {
            var model = db.v_DB_View;

            return Json( new { data = model } ,JsonRequestBehavior.AllowGet);
        }

Format of JSON Output from GetView():

{ data : [

{Column1: "Value1",
Column2: "Value2",
....} ,

{Column1: "Value1",
Column2: "Value2",
... }, 

...

]}
3
  • 1
    What happens when you remove 'aoColumns' section in Datatable code? Commented Oct 18, 2016 at 21:58
  • Hi Vijai it works! (kind of) But I get this error "DataTables warning: Table id=parentTable - Requested unknown parameter for row 0, column 7 Commented Oct 18, 2016 at 22:10
  • Check if null value is returned from the Controller for column 7. Also check this link which already discussed about this problem, stackoverflow.com/questions/16539578/… Commented Oct 18, 2016 at 22:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.