customize callback

customize callback

m75sam75sa Posts: 132Questions: 30Answers: 0
edited February 2023 in Free community support

I have a table with server side processing values.
I would like to display a value from ajax server side process that shows some informations about the search result.

So let's suppose i have a value stored in a variable ($x = "value to pass") and let's suppose this var is declared into the server side processing file...
how to pass this value to the table, for example, in the footer or header?

into the ssp file i have at the end the following code:

$json_data = array(
            "draw"            => intval( $requestData['draw'] ),  
            "recordsTotal"    => intval( $totalData ), 
            "recordsFiltered" => intval( $totalFiltered ), 
            "data"            => $data,
            "cancellati"    => intval( $iso ) 
            );



echo json_encode($json_data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);

So basically I don't know how to call values declared into ajax file into the table (header or footer)... or into the pageinfo.

Any idea?
Thanks in advance

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Are you saying you want to return these values from your server script? If so use ajax.json() to get the latest Ajax response.

    Otherwise just use variables that can be accessed within the scope of your Datatable.

    Kevin

  • m75sam75sa Posts: 132Questions: 30Answers: 0

    i tried with this code but nothing happened, so i cannot see the alert content
    ...

    var table = $('#example').DataTable( {
        ajax: "data.json"
    } );
    
    table.on( 'xhr', function () {
        var json = table.ajax.json();
        alert( json.data.length +' row(s) were loaded' );
    } );
    
  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Since ajax is an asynchronous process so the table variable hasn't been defined yet when line 5 executes. You will probably see an error in the browser's console. See the examples in the xhr docs. Also note that the JSON is passed into xhr as json so you don't need the API.

    Kevin

Sign In or Register to comment.