DataTables: Cannot read property 'length' of undefined

前端 未结 11 1205
醉酒成梦
醉酒成梦 2020-12-13 05:15

I understand this a popular issue, and I have read all the similar questions here on Stack Overflow and other sites (including the datatables website).

To clarify, I

相关标签:
11条回答
  • 2020-12-13 06:02

    This is really late to the party, but none of the solutions above worked for me. I didn't want the "Found total xxx records" so I added info:false to the config. When I removed that everything worked.

    I should note that the first page loaded fine. When I hit next, the second page loaded, but immediately threw the above console error

    0 讨论(0)
  • 2020-12-13 06:03

    you can try checking out your fields as you are rendering email field which is not available in your ajax

    $.ajax({
      url: "url",
      type: 'GET',
      success: function(data) {
        var new_data = {
          "data": data
        };
        console.log(new_data);
      }
    });

    0 讨论(0)
  • 2020-12-13 06:05

    It's even simpler: just use dataSrc:'' option in the ajax defintion so dataTable knows to expect an array instead of an object:

        $('#pos-table2').DataTable({
                      processing: true,
                      serverSide: true,
                      ajax:{url:"pos.json",dataSrc:""}
                }
        );
    

    See ajax options

    0 讨论(0)
  • 2020-12-13 06:14

    In my case, i had to assign my json to an attribute called aaData just like in Datatables ajax example which data looked like this.

    0 讨论(0)
  • 2020-12-13 06:18

    When you have JSON data then the following error appears enter image description here

    A better solution is to assign a var data for the local json array object, details see: https://datatables.net/manual/tech-notes/4

    This is helps you to display table contents.

     $(document).ready(function(){   
    
            $('#customer_table').DataTable( {
             "aaData": data,
    
               "aoColumns": [{
                                "mDataProp": "name_en"
                            }, {
                                "mDataProp": "phone"
                            }, {
                                "mDataProp": "email"
                            }, {
                                "mDataProp": "facebook"
                            }]
                });
            });
    
    0 讨论(0)
提交回复
热议问题