Server-Side - does not work well

Server-Side - does not work well

ostmalostmal Posts: 102Questions: 33Answers: 0

Hello!
Since I have a very large table (about 200,000), I had to look in the Server-Side direction.
I decided to test it. The source is a small table of 27 rows.

Example:
http://www.a0250268.xsph.ru/index.php/server-side

Here I read that it is enough to enable the "serverSide: true"option:
https://datatables.net/manual/server-side
That's what I did.
As a result,:
- pagination does not work
- sorting doesn't work

JS

(function($){
$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: '/abc_crm/dt/my/server_side/server_side.php',
        table: '#aaa_kv',
        fields: [
            {
                label: "fio:",
                name: "fio_name"
            }
        ]
    } );

    var table = $('#aaa_kv').DataTable( {
        dom: 'Bfrtip',
        ajax: '/abc_crm/dt/my/server_side/server_side.php',
        processing: true,
        serverSide: true,
        paging: true,
        columns: [
            {data: "id"},
            {data: "fio_name"}
        ],
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    } );

} );
}(jQuery));

PHP

<?php
// DataTables PHP library and database connection
include( "../../prog/php/lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'aaa_fio', 'id' )
    ->fields(
        Field::inst( 'id' ),
        Field::inst( 'fio_name' )
    )
    ->process( $_POST )
    ->json();

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Are you using the server-side script from this example?
    https://datatables.net/examples/data_sources/server_side.html

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    No. I'll try it now.

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    I tried it, it does not work (((. For testing, I reduced the number of fields to one. The data does not come. I tried the array member "host "in two variants:" localhost " (now) and the absolute hostname.
    PHP:

    <?php
    // DB table to use
    $table = 'aaa_fio';
    
    // Table's primary key
    $primaryKey = 'id';
    
    $columns = array(
        // array( 'db' => 'id', 'dt' => 0 ),
        array( 'db' => 'fio_name',  'dt' => 1 )
    );
    
    // SQL server connection information
    $sql_details = array(
        'user' => 'a0250268_app_joomla_0',
        'pass' => '************',
        'db'   => 'a0250268_app_joomla_0',
        // 'host' => 'a0250268.xsph.ru'
        'host' => 'localhost'
    );
    
    
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * If you just want to use the basic configuration for DataTables with PHP
     * server-side, there is no need to edit below this line.
     */
    
    require( 'ssp.class.php' );
    
    echo json_encode(
        SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    
    
  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Check your browser console for errors.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    As tangerine said, that link you said isn't loading and is giving console errors. You probably haven't included the JS/CSS for the Buttons extension.

    Colin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    I'm sorry, there really was a mistake in JS, but even after fixing it, I don't get data from the server:
    http://www.a0250268.xsph.ru/index.php/server-side

    (function($){
    $(document).ready(function() {
        var table = $('#aaa_kv').DataTable( {
            dom: 'frtip',
            ajax: '/abc_crm/dt/my/server_side/server_side.php',
            processing: true,
            serverSide: true,
            paging: true,
            columns: [
                // {data: "id"},
                {data: "fio_name"}
            ]
        } );
    } );
    }(jQuery));
    
    <?php
    // DB table to use
    $table = 'aaa_fio';
    
    // Table's primary key
    $primaryKey = 'id';
    
    $columns = array(
        array( 'db' => 'fio_name',  'dt' => 0 )
    );
    
    // SQL server connection information
    $sql_details = array(
        'user' => 'a0250268_app_joomla_0',
        'pass' => '***',
        'db'   => 'a0250268_app_joomla_0',
        // 'host' => 'a0250268.xsph.ru'
        'host' => 'localhost'
    );
    
    
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * If you just want to use the basic configuration for DataTables with PHP
     * server-side, there is no need to edit below this line.
     */
    
    require( 'ssp.class.php' );
    
    echo json_encode(
        SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    
    
  • ostmalostmal Posts: 102Questions: 33Answers: 0

    That is, some data is coming, but it is clearly not the JSON format (((

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    I'm still getting the error "Uncaught Unknown button type: print".

    Colin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Can the memory cache? My console is clean - it doesn't output anything.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Change:

    ajax: '/abc_crm/dt/my/server_side/server_side.php',
    

    to be:

    ajax: {
      url: '/abc_crm/dt/my/server_side/server_side.php',
      type: 'post'
    }
    

    The issue is that you had ->process( $_POST ), but by default DataTables will send a GET request.

    Allan

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    See also this example which does exactly that.

    Allan

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Thank you very much!
    1. In JS "post"
    2. Returned the old classic PHP file:

    <?php
    // DataTables PHP library and database connection
    include( "../../prog/php/lib/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'aaa_fio', 'id' )
        ->fields(
            Field::inst( 'id' ),
            Field::inst( 'fio_name' )
        )
        ->process( $_POST )
        ->json();
    
    
Sign In or Register to comment.