I trying to insert json collection in datatable using jQuery. This is my code:
I trying to insert json collection in datatable using jQuery. This is my code:
function reloadseekers(vacancy){
if (vacancy) {
var seeker=[];
$.ajax({
url: '/getseekers/' + vacancy,
method: "GET",
dataType: "json",
cache: false,
success: function (data) {
$.each(data.appSeekers, function (index) {
seeker [index]={
'ssn': data.appSeekers[index].ssn,
'full name': data.appSeekers[index].first_name + ' ' + data.appSeekers[index].second_name + ' ' +
data.appSeekers[index].middle_name + ' ' + data.appSeekers[index].last_name,
'primary phone': data.appSeekers[index].phone_1,
'secondary phone': data.appSeekers[index].phone_2,
'Total evaluation': data.appSeekers[index].evaluation.total_evaluation,
'Employment Notes': data.appSeekers[index].evaluation.employment_notes,
'Referral count': data.appSeekers[index].redirection_Count,
'communication': extractcommunication(data.appSeekers[index].communications)
};
});
$('#evaluated_list_table').dataTable(
{
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"data": seeker,
});
The datatable stile empty!!!!
any help?
This discussion has been closed.
Answers
Since you are using object data you will need to use
columns.datato define the columns. I would eliminate the $.each() loop and use change thedataoption to"data": data.appSeekers. Then definecolumns.datausing the original object property names.See the Data Sources docs for more details. See this example for ajax loaded objects.
See this example for using
columns.renderto combining the name fields into one column.Kevin
Thanks Kevin for you answer. I modified the code as you answer:
if (vacancy) {
var seeker;
$.ajax({
url: '/getseekers/' + vacancy,
method: "GET",
dataType: "json",
cache: false,
success: function (data) {
$('#evaluated_list_table').dataTable(
{
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"data": data.appSeeker,
"columns": [
{ "title": "SSN" },
{ "data": "ssn"},
{ "title": "First Name" },
{ "data": "first_name"},
{ "title": "Primary phone" },
{ "data": "phone_1"},
{ "title": "Secondary phone" },
{ "data": "phone_2"},
{ "title": "Total evaluation" },
{ "data": "total_evaluation"},
{ "title": "Employment notes" },
{ "data": "employment_notes"},
{ "title": "Referral count" },
{ "data": "referral_count"},
]
});
but i still have the the table with No data available in table!!!
Thanks Dear
@Dzahi is this still an issue? If so, can you post a few lines of the data returned from the ajax command, please.
Colin
Thanks dear, the issue solved as Kevin presented.. thanks,, i have another problem with tabledit used in datatables,,,
Yep, I replied on that other thread,
Colin