No pagination when using PHP library

No pagination when using PHP library

globalplaneglobalplane Posts: 70Questions: 12Answers: 0
edited May 2023 in Free community support

Link to test case: https://comprehensibleinputwiki.com/ciwlibrary/test_case.php (Careful, without pagination this loads >10,000 rows at once.)
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

As I'm getting into tens of thousands of rows, I decided to start server-side processing. I use SearchPanes, and saw that the PHP library is recommended for this purpose.

I didn't change much of the client javascript, except to set serverSide: true:

                let table = new DataTable('#library-table', {
                    dom: 'Plfrtip',
                    serverSide: true,
                    ajax: 'newvidadmin.php',
                    deferRender: true,
                    "columns": [
                        { "data": "vid" },

                        { "data": "title" },

                        { "data": "channelTitle" },

                        { "data": "level" ,
                          "class": "level" },

                        { "data": "language" ,
                          "class": "language" },

                        { "data": "enabled" ,
                          "class": "enabled" },

                    ],
                    searchPanes: {
                        viewTotal: true,
                    },
                    "columnDefs": [
                        { 
                            "targets": [5], "orderable": false 
                        }, 
                        {
                            "targets": 3,
                            "createdCell": function (td, cellData, rowData, row, col) {
                                $(td).attr('data-field', 'level');
                            }
                        },
                        {
                            "targets": 4,
                            "createdCell": function (td, cellData, rowData, row, col) {
                                $(td).attr('data-field', 'language');
                            }
                        },
                        {
                            "targets": 5,
                            "createdCell": function (td, cellData, rowData, row, col) {
                                $(td).attr('data-field', 'enabled');
                            }
                        },
                    ]
                });

And here is the server-side code:

<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

include( "/var/www/comprehensibleinputwiki.com/html/editor-php/lib/DataTables.php" );
 
use 
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\SearchPaneOptions;


$editor = Editor::inst( $db, 'main_collection', 'main_index' )
    ->fields(
        Field::inst( 'main_index' ),
        Field::inst( 'id' , 'vid'),
        Field::inst( 'channel', 'channelTitle' )
            ->searchPaneOptions( SearchPaneOptions::inst() ),
        Field::inst( 'language_id', 'language' ),
        Field::inst( 'title' ),
        Field::inst( 'level' ),
        Field::inst( 'enabled' )

    )
    ->process( $_POST )
    ->json();

But there's no pagination. It loads every row onto the page from the start. The page buttons don't do anything, and the text at the bottom says "Showing 0 to 0 of 0 entries (filtered from NaN total entries)". What am I missing?

Do I need to install the Editor package along with Datatables for this to work properly?

This question has an accepted answers - jump to answer

Answers

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

    See if this blog answers your questions.

    Kevin

  • globalplaneglobalplane Posts: 70Questions: 12Answers: 0

    Oh, I had to set type: "POST" on the client! Thanks!

Sign In or Register to comment.