using array of objects with rowCallBack

using array of objects with rowCallBack

veonicarinveonicarin Posts: 1Questions: 1Answers: 0
edited September 2019 in Free community support

Hi all, i want to ask, I've made a valid DataTable with this data Which works, but doesn't seem like the best way to go about things, and this is my code :smile:

$(document).ready(function() {
  var tableLogAlarm = $('#tbEvent').DataTable({
    "pageLength": 10,
    "responsive": true,
    "dom": '<"html5buttons"B>lTfgitp',
    "buttons": [{
        extend: 'copy'
      },
      {
        extend: 'csv'
      },
      {
        extend: 'excel',
        title: 'listEvent'
      }
    ],
    "bProcessing": true,
    "sAjaxSource": "data/getData.php?cek=listEventForTable",
    "aoColumns": [{
        mData: 'requestor_dept'
      },
      {
        mData: 'additional_msg'
      },
      {
        mData: 'oss_nename'
      }
    ],
    "rowCallback": function(row, data, index) {
      var requestor_dept = data.requestor_dept; // this is work
      var additional_msg = data.additional_msg; // this is work
      var oss_nename = data.data[].oss_nename; //  this is not work this is the problem  :neutral:

      $node = this.api().row(row).nodes().to$();
    }
  });
});

my array of objects json

{
   "sEcho":1,
   "iTotalRecords":5,
   "iTotalDisplayRecords":5,
   "aaData":[
      {

         "requestor_dept":"User",
         "additional_msg":null,
      },
      {
         "data":[
            {
               "oss_siteid":"JKP047",
               "oss_nename":"JKP047",
               "jarak":"0.10"
            },
         ],
         "reuslt":"OK"
      },

how to get data oss_nename ?
thank you :smile:

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    Since data.data is an array and it looks like you want to access element 0 of the array try data.data[0].oss_nename;.

    Kevin

This discussion has been closed.