Server-side not returning data

Server-side not returning data

mcodermcoder Posts: 19Questions: 9Answers: 0

So, I am in the process of trying to switch from client-side processing to server-side processing, but I am having problems getting the data to appear. I get an error message:

Uncaught TypeError: Cannot read properties of undefined (reading 'cell')

Link to test case
The test case isn't very useful as it doesn't run server-side, nor does it show all of my files.
live.datatables.net/geqisica/1/edit

Debugger code (avudoh):

Error messages shown:
I have the ssp.class.php file in the same folder as the server_processing.php file. When I try to load the page I get the processing message then the console shows the following:


jQuery.Deferred exception: Cannot read properties of undefined (reading 'cell') TypeError: Cannot read properties of undefined (reading 'cell')
    at _fnDrawHead (http://localhost:8000/DataTables/datatables.js:63061:59)
    at _fnInitialise (http://localhost:8000/DataTables/datatables.js:64440:3)
    at loadedInit (http://localhost:8000/DataTables/datatables.js:60952:6)
    at HTMLTableElement. (http://localhost:8000/DataTables/datatables.js:60965:5)
    at Function.each (http://localhost:8000/js/jquery-3.5.1.js:381:19)
    at jQuery.fn.init.each (http://localhost:8000/js/jquery-3.5.1.js:203:17)
    at jQuery.fn.init.DataTable [as dataTable] (http://localhost:8000/DataTables/datatables.js:60522:8)
    at jQuery.fn.init.$.fn.DataTable (http://localhost:8000/DataTables/datatables.js:74966:18)
    at HTMLDocument. (http://localhost:8000/paging2.php:88:16)
    at mightThrow (http://localhost:8000/js/jquery-3.5.1.js:3762:29) undefined
jQuery.Deferred.exceptionHook @ jquery-3.5.1.js:4046
jquery-3.5.1.js:4055 Uncaught TypeError: Cannot read properties of undefined (reading 'cell')
    at _fnDrawHead (datatables.js:63061)
    at _fnInitialise (datatables.js:64440)
    at loadedInit (datatables.js:60952)
    at HTMLTableElement. (datatables.js:60965)
    at Function.each (jquery-3.5.1.js:381)
    at jQuery.fn.init.each (jquery-3.5.1.js:203)
    at jQuery.fn.init.DataTable [as dataTable] (datatables.js:60522)
    at jQuery.fn.init.$.fn.DataTable (datatables.js:74966)
    at HTMLDocument. (paging2.php:88)
    at mightThrow (jquery-3.5.1.js:3762)
favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)

Description of problem:

I am initially just trying to load a few fields in a table using the server_processing.php file from the example page. https://datatables.net/examples/server_side/simple.html

In the end I will not even be able to use the server_processing.php as I will need to use joined tables in the query. I also need to use the filtering from the on screen filters. (But I need to at least prove the simple case works).

HTML File


<script>
$(document).ready(function() {
        $('#example').DataTable( {
                "processing": true,
                "serverSide": true,
                "ajax": "/scripts/server_processing.php"
        } );
} );


<table id="example" class="display" style="width:100%">
        <thead>
                <tr>
                        <th>IP Address</th>
                        <th>Port</th>
                        <th>Protocol</th>
                <tr>
        <thead>
</table>

server_processing.php: The issue I am having with this script is that the tables in this database use compound keys and not an identifier field. I am unsure how to specify the $primaryKey value in this script.


// DB table to use
$table = 'ports';

// Table's primary key
$primaryKey = 'ip_address';
// `ip_address`,`port`,`protocol`

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
    array( 'db' => 'ip_address', 'dt' => 0 ),
    array( 'db' => 'port',       'dt' => 1 ),
    array( 'db' => 'protocol',   'dt' => 2 )
);

// SQL server connection information
$sql_details = array(
    'user' => 'xxx',
    'pass' => 'xxx',
    'db'   => 'xxx',
    'host' => '127.0.0.1'
);

require( 'ssp.class.php' );

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

So at this point:
1. I am unsure how to set a multi-field key in the script
2. I am unsure why I am not getting data returned to the table

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    Answer ✓

    You have a type in the table:

    <table id="example" class="display" style="width:100%">
            <thead>
                    <tr>
                            <th>IP Address</th>
                            <th>Port</th>
                            <th>Protocol</th>
                    <tr>
            <thead>
    </table>
    

    On line 7 you should have </tr>.

    Kevin

Sign In or Register to comment.