Editor PHP Library with Scroller Extension - Offset and Limits
Editor PHP Library with Scroller Extension - Offset and Limits
As you know, the Scroller Extension sends the row limits and offsets to the ajax source.
I see in the code for the Editor PHP Library that there is a function to handle, i.e. set the offset and limits
private function _ssp_limit ( $query, $http )
{
if ( $http['length'] != -1 ) { // -1 is 'show all' in DataTables
$query
->offset( $http['start'] )
->limit( $http['length'] );
}
}
My PHP file looks like this:
<?php
include( $_SERVER['DOCUMENT_ROOT'] .'/common/php/DataTables.php' );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
Editor::inst( $db, 'contact', 'id' )
->fields(
Field::inst( 'id' )->set( false ),
Field::inst( 'name' )->set( false ),
Field::inst( 'reference' )->set( false ),
Field::inst( 'type' ),
Field::inst( 'entity' ),
Field::inst( 'firstname' ),
Field::inst( 'lastname' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'companyid' )
)
->where( 'companyid', $_REQUEST['companyid'])
->process( $_POST )
->json();
<?php
>
```
?>
As you can see from the header variables, the **start** and **length** are being sent to the PHP file,
```xml
. . .
columns[4][search][regex]:false
start:0
length:63
search[value]:
search[regex]:false
. . .
The returned data, however, contains ALL the rows.
Questions:
- Any comments or suggestions?
- How do I debug the query generated by the Editor PHP Library?
If it helps, here are my datable defaults and table initialization code:
browseAddressBookTable = $('#browse-addressbook-table').DataTable({
ajax: {
url: '/addressbook/data/table.contact.php',
data: { companyid: company.id }
},
dom: 'BtS',
scrollY: options.tableHeight,
buttons: [],
buttons: [
{
text: 'Add new button',
action: function ( e, dt, node, config ) {
DisplayMessage("Add goes here");
}
}
],
.....
$.extend( $.fn.dataTable.defaults, {
lengthChange: false,
language: {
zeroRecords: 'No records found',
loadingRecords: 'Loading...'
},
ordering: false,
paging: true,
processing: true,
rowId: 'id',
serverSide: true,
scroller: {
loadingIndicator: true
},
scrollX: false,
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
OK - finally tracked it down.
The $data array in the source code was empty because there was no POST data. I was sending via a GET request.
I changed the following in my PHP file:
to
And all is working.
Another way of doing it is to tell DataTables to make the request using POST - which is shown here.
Allan