"No data available" message getting displayed in datatable.
"No data available" message getting displayed in datatable.
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
Hi @atish,
When you say, the data is in that form, you're pointing DataTables to:
so, is that data in
d
of the result set? i.e.Cheers,
Colin
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
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 yoursuccess
function. It should be an array of objects. Is that what you have?Kevin
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
Yep, but as Kevin said that's a string - note the double-quotes around the square brackets.
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