DatatTable Showing "No data available in table" but list populated

DatatTable Showing "No data available in table" but list populated

helderfchelderfc Posts: 2Questions: 1Answers: 0
edited March 2021 in Free community support

HI,

I have a List of values with data but my datatable show the No data Available.

this is mu script:

   $(document).ready(function () {
             $.ajax({
                 url: 'List.aspx/GetClubes',
                 type: 'GET',
                 contentType: 'application/json; charset=utf-8',
                 datatype: 'json',
                 success: function (data) {
                     $('#minhatabela').dataTable({
                         datasrc: data,
                         columns: [

                             { 'data': 'Nome' },
                             { 'data': 'Telefone' },
    
                         ]
                     });
                 }
             });
         });

My aspx return a List<class>.

Can you help me?

Thank you

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 21,179Questions: 26Answers: 4,923

    Try using the data option. instead of datasrc: data, use data: data. There is not an option called dataSrc. There is a ajax.dataSrc option if you are using the ajax option but you are not.

    Kevin

  • helderfchelderfc Posts: 2Questions: 1Answers: 0

    HI kthorngren, i've change to dataSrc as a test, I have now data and is the same problem.
    when I load my page, it stops in the server side script and loads the List from my database with 247 records.

    In the datatable appears No data Available

  • kthorngrenkthorngren Posts: 21,179Questions: 26Answers: 4,923

    Maybe you need to use JSON.parse() to parse the JSON response into a Javascript object. Everything else looks ok in your code. It just needs debugged to verify the response is what you expect. You can use the browser's network inspector or debug the data variable in the success function. Or post a link to your page or a test case so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.