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",
... }, 

...

]}
MrL
  • 348
  • 5
  • 24
  • 1
    What happens when you remove 'aoColumns' section in Datatable code? – Vijai Oct 18 '16 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 – MrL Oct 18 '16 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, http://stackoverflow.com/questions/16539578/datatables-warning-requested-unknown-parameter-0-from-the-data-source-for-row – Vijai Oct 18 '16 at 22:37

0 Answers0