Server-Side - does not work well
Server-Side - does not work well
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
Are you using the server-side script from this example?
https://datatables.net/examples/data_sources/server_side.html
No. I'll try it now.
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:
Check your browser console for errors.
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
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
That is, some data is coming, but it is clearly not the JSON format (((
I'm still getting the error "Uncaught Unknown button type: print".
Colin
Can the memory cache? My console is clean - it doesn't output anything.
Change:
to be:
The issue is that you had
->process( $_POST )
, but by default DataTables will send a GET request.Allan
See also this example which does exactly that.
Allan
Thank you very much!
1. In JS "post"
2. Returned the old classic PHP file: