help steer me in the right direction (noob to javascript + jquery)

help steer me in the right direction (noob to javascript + jquery)

booboybooboy Posts: 2Questions: 1Answers: 0

Hello Everyone,

Can someone help steer me in the right direction to make the tables display the data properly? I have tried following the examples provided here: https://datatables.net/examples/ajax/objects.html and https://datatables.net/manual/ajax . I am receiving the error:

DataTables warning: table id=wiperdata - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

I followed a trail of Google and StackedOverflow posts about it but have been unable to figure out the fix thus far. Any tips, even small tips are greatly appreciated and can only help me improve my knowledge. Here is my code:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <title>DriveWiper</title>
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
        <style type="text/css">
        </style>
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"> </script>
        
        <script type="text/javascript">

$(document).ready(function() {
    $('#wiperdata').DataTable( {
    ajax: { 
            processing: true,
            url: "status.json", 
            dataSrc: "drivebays", 
            datatype: "json"
    },
    columns: [
            { drivebays: "drivebay" },
            { drivebays: "start" },
            { drivebays: "model" },
            { drivebays: "serial" },
            { drivebays: "size"  },
            { drivebays: "progress" },
        { drivebays: "smart" }
        ]
    } );
} );

        </script>
    </head>
<body>
<table id="wiperdata" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Drive Bay</th>
                <th>Start</th>
                <th>Model</th>
                <th>Serial</th>
                <th>Size</th>
                <th>Progress</th>
        <th>Smart</th>
            </tr>
        </thead>
    <tbody>
    </tbody>
        <tfoot>
            <tr>
                <th>Drive Bay</th>
                <th>Start</th>
                <th>Model</th>
                <th>Serial</th>
                <th>Size</th>
                <th>Progress</th>
        <th>Smart</th>
            </tr>
        </tfoot>
    </table>
</body>
</html>

the json data:

{ "drivebays": [
{
  "drivebay": 0,
  "start": "Fri Jul 21 18:44:32 CDT 2017",
  "starttimet": 1500680672,
  "model": "MBA3300RC",
  "serial": "omitted",
  "fwrev": "0103",
  "size": 300000000000,
  "sizemb": "300000 MBytes (300 GB)",
  "smart": "SMART Health Status: OK",
  "progress": "10.62%",
  "currentrate": "118 MB/s",
  "averagerate": "109 MB/s"
},
{
  "drivebay": 1,
  "start": "Fri Jul 21 18:44:26 CDT 2017",
  "starttimet": 1500680666,
  "model": "WDC WD5003AZEX-00MK2A0",
  "serial": "omitted",
  "fwrev": "01.01A01",
  "size": 500107862016,
  "sizemb": "500107 MBytes (500 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "10.55%",
  "currentrate": "65536 B/s",
  "averagerate": "175 MB/s"
},
{
  "drivebay": 2,
  "start": "Fri Jul 21 18:44:28 CDT 2017",
  "starttimet": 1500680668,
  "model": "ST3000DM001-9YN166",
  "serial": "omitted",
  "fwrev": "CC4B",
  "size": 3000592982016,
  "sizemb": "3000592 MBytes (3000 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "1.85%",
  "currentrate": "65536 B/s",
  "averagerate": "184 MB/s"
},
{
  "drivebay": 3,
  "start": "Fri Jul 21 18:44:25 CDT 2017",
  "starttimet": 1500680665,
  "model": "ST3500418AS",
  "serial": "omitted",
  "fwrev": "CC46",
  "size": 500107862016,
  "sizemb": "500107 MBytes (500 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "6.15%",
  "currentrate": "65536 B/s",
  "averagerate": "102 MB/s"
},
{
  "drivebay": 4,
  "start": "Fri Jul 21 18:49:40 CDT 2017",
  "starttimet": 1500680980,
  "model": "WDC WD5003AZEX-00K1GA0",
  "serial": "omitted",
  "fwrev": "80.00A80",
  "size": 500107862016,
  "sizemb": "500107 MBytes (500 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "26.04%",
  "currentrate": "189 MB/s",
  "averagerate": "197 MB/s"
},
{
  "drivebay": 5,
  "start": "Fri Jul 21 18:44:23 CDT 2017",
  "starttimet": 1500680663,
  "model": "TOSHIBA MG03ACA200",
  "serial": "omitted",
  "fwrev": "FL1A",
  "size": 2000398934016,
  "sizemb": "2000398 MBytes (2000 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "2.48%",
  "currentrate": "65536 B/s",
  "averagerate": "165 MB/s"
},
{
  "drivebay": 6,
  "start": "Fri Jul 21 18:44:21 CDT 2017",
  "starttimet": 1500680661,
  "model": "ST500DM002-1BD142",
  "serial": "omitted",
  "fwrev": "KC45",
  "size": 500107862016,
  "sizemb": "500107 MBytes (500 GB)",
  "smart": "SMART overall-health self-assessment test result: PASSED",
  "progress": "7.42%",
  "currentrate": "154 MB/s",
  "averagerate": "119 MB/s"
},
{
  "drivebay": 7,
  "start": "Fri Jul 21 18:44:15 CDT 2017",
  "starttimet": 1500680655,
  "model": "HUS151473VLS300",
  "serial": "omitted",
  "fwrev": "A48B",
  "size": 73407820800,
  "sizemb": "73407 MBytes (73 GB)",
  "smart": "SMART Health Status: OK",
  "progress": "36.43%",
  "currentrate": "84410 kB/s",
  "averagerate": "86003 kB/s"
}
]}

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Try changing this:

        columns: [
                { drivebays: "drivebay" },
                { drivebays: "start" },
                { drivebays: "model" },
                { drivebays: "serial" },
                { drivebays: "size"  },
                { drivebays: "progress" },
            { drivebays: "smart" }
            ]
    

    to this:

        columns: [
                { data: "drivebay" },
                { data: "start" },
                { data: "model" },
                { data: "serial" },
                { data: "size"  },
                { data: "progress" },
            { data: "smart" }
            ]
    

    Kevin

  • booboybooboy Posts: 2Questions: 1Answers: 0

    Thank you. That solved it. Much appreciated! <3

This discussion has been closed.