user2622132
user2622132

Reputation: 49

Json ajax data on a datatable Jquery

I am new to jquery. i have a datatable with data at the loading time. after searching data i need to remove that data from the datatable and display the searched data on that table. i cleared the datatable by using

app.common.genericAjaxCall("POST", '\getGroupsajax=true"', data, function(data) {

                dataGrid = dataGrid.fnClearTable();
                dataGrid = $('#dataGrid').dataTable().fnAddData(data);
                alert('hidata');
            }

but it is not giving the correct result.

My json output is:

Object  { "aaData" : [{"id":37,"attemptId":1,"name":"Group1","emailIds":null,"type":"Forward","status":1,"scheduleDate":"03/10/2014 21:50 PM","sheduledBy":null,"startDate":null,"endDate":null,"action":0}]}

there are more than one results on this array. Then i need to display the data. data get from a json ajax call. How to fix this. greatly appreciate your help

Upvotes: 0

Views: 3569

Answers (1)

mainguy
mainguy

Reputation: 8331

Works for me using this initilisation:

  json = '{ "aaData" : [{"id":37,"attemptId":1,"name":"Group1","emailIds":null,"type":"Forward","status":1,"scheduleDate":"03/10/2014 21:50 PM","sheduledBy":null,"startDate":null,"endDate":null,"action":0}]}';

  parsedJson= JSON.parse(json);
  var otable = $("#datatable").dataTable();

  otable.fnClearTable();

  $.each(parsedJson.aaData, function(key, value) {
    otable.dataTable().fnAddData([
      value.id,
      value.attemptId,
      value.name,
      value.emailIds,
      value.type,
      value.status,
      value.scheduleDate,
      value.sheduledBy,
      value.startDate,
      value.endDate,
      value.action,
    ]);
  })

If OBJECT is realy some text of your output, remove it:-)

Working Plunker

Upvotes: 0

Related Questions