Why doesn't server side pagination work?

Why doesn't server side pagination work?

bububsbububs Posts: 1Questions: 1Answers: 0

Hi everyone, I have a problem with the server side where it shows me all the rows of the table (3 columns) without pagination.
I show you the source codes:
[script.js]
$ ('#my_table').DataTable ({
       "deferRender": true,
       "searching": false,
       "ordering": false,
         "processing": true,
         "serverSide": true,
         "ajax": {
             url: "ajax_response.php",
             type: "post",
             error: function () {
             $ ("#my_table").css("display", "none");
         }
         }
});

[ajax_response.php]
$data = array ();

for($i = 0; $i <10000; $i++)
$data[$i] = array ( $i . "- 1", $i . "- 2", $i . "- 3" );

$json = array (
"draw" => intval( $_REQUEST['draw'] ),
"recordsTotal" => count($data),
"recordsFiltered" => count($data),
"data" => $data
);

echo json_encode($json);

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    The server side script is responsible for returning the number of rows based on the parameters sent via the ajax request. See this doc:
    https://datatables.net/manual/server-side

    There are a number of parameters that the server side script needs to monitor for things like sorting and searching. But in the simplest case the start and length parameters provide the paging info which the server side script uses to return the desired rows.

    In your case it looks like your script is return 10,000 rows. I'm not familiar with php but your for loop needs to take this into consideration. Maybe something like this:

    for($i = $start; $i <$length; $i++)

    Kevin

This discussion has been closed.