"No data available" message getting displayed in datatable.

"No data available" message getting displayed in datatable.

AtishAtish Posts: 6Questions: 2Answers: 0
edited July 2019 in Free community support

Hi,
I have a simple datatable where in I am getting the msg "No data available" even when data is available (I can see the data in console.)

Following is the code I have written.

DATATABLE CODE:
Success part of ajax cal

success: function (result) {
                    $('#example').DataTable({
                        "data": result.d,
                        "columns": [
                            { "data": "PFA_NAME" },
                            { "data": "AGENT_CODE" },
                            { "data": "MBG_NORMS" },
                            { "data": "PERSISTENCY_NORMS" },
                            { "data": "FINAL_STATUS" },
                            { "data": "ACTION_BUCKET" },
                            { "data": "LIVES" },
                            { "data": "AEP" },
                            { "data": "NOP" },
                            { "data": "PREMIUM" },
                            { "data": "ACTION" }
                        ]
                    });
                }

DATA:
My data is in the following form.
[
{"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CODE":"A34568","MBG_NORMS":"MBG Fufilled","PERSISTENCY_NORMS":"Persistency Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Achieved","NOP":"Achieved","PREMIUM":"Achieved","ACTION":"Warning/ Termination letter sent"},

{"PFA_NAME":"Aashalesha Sanjay Pawar","AGENT_CODE":"A24940","MBG_NORMS":"MBG Not Fulfilled","PERSISTENCY_NORMS":"Persistency Not Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Not Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Not Achieved","NOP":"Not Achieved","PREMIUM":"Not Achieved","ACTION":"Warning/ Termination letter sent"}
]

HTML:

Any help would be appreciated.

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

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @atish,

    When you say, the data is in that form, you're pointing DataTables to:

    "data": result.d
    

    so, is that data in d of the result set? i.e.

    {d:[
    {"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CODE":"A34568","MBG_NORMS":"MBG Fufilled","PERSISTENCY_NORMS":"Persistency Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Achieved","NOP":"Achieved","PREMIUM":"Achieved","ACTION":"Warning/ Termination letter sent"},
    
    {"PFA_NAME":"Aashalesha Sanjay Pawar","AGENT_CODE":"A24940","MBG_NORMS":"MBG Not Fulfilled","PERSISTENCY_NORMS":"Persistency Not Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Not Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Not Achieved","NOP":"Not Achieved","PREMIUM":"Not Achieved","ACTION":"Warning/ Termination letter sent"}
    ]}
    

    Cheers,

    Colin

  • AtishAtish Posts: 6Questions: 2Answers: 0
    edited July 2019

    Hi colin,

    My result object is as follows:
    {d: "[{"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CO…ed","ACTION":"Warning/ Termination letter sent"}]"}

    Hence using result.d in "data".

    Thanks,
    Atish

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    The problem is the d object is a string not an array: "[{"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CO…ed","ACTION":"Warning/ Termination letter sent"}]".

    Its confusing what your result.d actually is. Using Colin's example here it works:
    http://live.datatables.net/yuqizara/1/edit

    Maybe start by using console.log(result.d); in your success function. It should be an array of objects. Is that what you have?

    Kevin

  • AtishAtish Posts: 6Questions: 2Answers: 0

    My console.log(result.d) gives the following :

    [
    {"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CODE":"A34568","MBG_NORMS":"MBG Fufilled","PERSISTENCY_NORMS":"Persistency Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Achieved","NOP":"Achieved","PREMIUM":"Achieved","ACTION":"Warning/ Termination letter sent"},

    {"PFA_NAME":"Aashalesha Sanjay Pawar","AGENT_CODE":"A24940","MBG_NORMS":"MBG Not Fulfilled","PERSISTENCY_NORMS":"Persistency Not Fulfilled","FINAL_STATUS":"MBG & Persistency Norm Not Fulfilled","ACTION_BUCKET":"=>37 months but less than 48 Months","LIVES":"Not Achieved","AEP":"Not Achieved","NOP":"Not Achieved","PREMIUM":"Not Achieved","ACTION":"Warning/ Termination letter sent"}
    ]

    Atish

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    {d: "[{"PFA_NAME":"RAGHAVENDRA SWAMY ARADHYA","AGENT_CO…ed","ACTION":"Warning/ Termination letter sent"}]"}
    

    Yep, but as Kevin said that's a string - note the double-quotes around the square brackets.

  • AtishAtish Posts: 6Questions: 2Answers: 0

    The return type of the method which the ajax call is hitting is Json string.Hence result.d is string.

    JSON.Parse(result.d) worked !!!!!

    Thanks for the help

This discussion has been closed.