Requested unknown parameter 'hostname from the data source when using fnAddRow

Requested unknown parameter 'hostname from the data source when using fnAddRow

FogestFogest Posts: 7Questions: 1Answers: 0

I am getting the error: "DataTables warning (table id = 'servicesTable'): Requested unknown parameter 'hostname' from the data source for row 6" when I try to add a template row to my table. I essentially want a blank row with a dropdown to select a "service" and a button "Add" to add the row to the database (and be altered to be non-editable in the table, but this I can do). I am confused why the adding is not working here. I seem to have all 6 of the columns correctly being adding in my fnAdd function.

Here is my javascript I have:

    $('#servicesTable').dataTable({
        'aaData' : servicesJson['registered_services'],
        'aoColumns': [
            { "sTitle": "Hostname", sName: "host", sWidth: "30%", sClass: 'host', mData: "hostname"},
            { "sTitle": "Service", sName: "service", sWidth: "30%", sClass: 'service', mData: "serviceName"},
            { "sTitle": "Monitored?", sName: "monitored", sWidth: "10%", sClass: 'monitored', mData: function(source) {
                if(typeof source.active === 'undefined')
                    return '';
                var monitor = source.active;
                if(monitor == 1)
                    return "<input type='checkbox' class='monitor' name='monitored' checked />";
                else
                    return "<input type='checkbox' class='monitor' name='monitored'/>";
            }},
            { "sTitle": "Status", sName: "status", sWidth: "15%", sClass: 'status', mData: "status"},
            { "sTitle": "URL", sName: "url", sWidth: "5%", sClass: 'url right', mData: function(source) {
                if(typeof source.url === 'undefined')
                    return '';
                return "<a class='ui-icon ui-icon-link' href='" + source.url +"'>NAGIOS</a>";
            }},
            {"sTitle": "Add/Remove", sName: "add-remove-new", sWidth: "15%", sClass: 'add-remove-new', mData: function() {
                return "<button class='add-remove-new' type='button'>Remove</button>";
            }},
        ],
        'bJQueryUI':true,
        'bInfo':false,
        'bPaginate':false,
        'bSort':true,
        'bFilter':true,
        'iDisplayLength':25,
        "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
            //function that is called everytime an element is added or a redraw is called
            //aData[] is an arraw of the values stored in datatables for the row
            //to change a row's html use $('td:eq('+index+')', nRow).html( html here ); where index is the index of the td element in the row
        }
    });

    addServicesRow();

    function addServiceRow() {
        //Get options for select.
        var options = '';
        for(var key in servicesJson['available_services']) {
            options += "<option value='" + key + "'>" + servicesJson['available_services'][key]['name'] + "</option>";
        }

        //DNS INPUT ROW
        $('#servicesTable').dataTable().fnAddData([
            "scspc545.cs",
            "<select class='services servicesList'>" +
            options +
            "</select>",
            "<input type='checkbox' class='monitor' name='monitored' checked />",
            "",
            "",
            "<button class='add-remove-new' type='button'>Add</button>"
        ]);
    }

And here is the JSON (not that it should matter for this):

{
  "available_services":[
    {
      "name":"Alive (ping)",
      "desc":"Used to ping the machine."
    },
    {
      "name":"APC Environmental Unit",
      "desc":"Helps the envrionment somehow?"
    },
    {
      "name":"APC UPS",
      "desc":"POWER!"
    },
    {
      "name":"Directory Services",
      "desc":"Directs us where to go."
    },
    {
      "name":"DNS Service",
      "desc":"Make everything accessible!"
    }
  ],
  "registered_services":[
    {
      "hostname":"machineName.example.com",
      "serviceName":"Alive (ping)",
      "active":"1",
      "status":"OK",
      "url":"https://nagios.example.com/"
    },
    {
      "hostname":"machineName.example.com",
      "serviceName":"APC Environmental Unit",
      "active":"1",
      "status":"WARNING",
      "url":"https://nagios.example.com/"
    },
    {
      "hostname":"machineName.example.com",
      "serviceName":"APC UPS",
      "active":"0",
      "status":"CRITICAL",
      "url":"https://nagios.example.com/"
    },
    {
      "hostname":"machineName.example.com",
      "serviceName":"Directory Services",
      "active":"0",
      "status":"MISSING SERIVCE",
      "url":"https://nagios.example.com/"
    },
    {
      "hostname":"machineName.example.com",
      "serviceName":"DNS Service",
      "active":"1",
      "status":"UNKNOWN",
      "url":"https://nagios.example.com/"
    }
  ],
  "messages":[
    {
      "type":"service",
      "status":"CRITICAL",
      "hostName":"machineName.example.com",
      "serviceName":"Temperature",
      "message":"ERROR MACHINE IS ON FIRE!",
      "acknowledged":"0",
      "since":"2015-05-18",
      "url":"https://nagios.example.com/"
    }
  ]
}

DataTables version: 1.9.4
jQuery version: 1.11.2
jQuery-ui version: 1.11.4

Answers

  • FogestFogest Posts: 7Questions: 1Answers: 0

    Solved. Had to switch to passing an object instead of array to fnAddRow as it is using mdata.

This discussion has been closed.