What you have to do on the server side is reading the limit
parameter of the request as well as either start
or page
. start
tells is the index of the first item to include, while page
is the index of the page... As you see, by default, Ext send them both. start
is easier to use with some databases like MySQL, because they use the same parameter.
In order to access request parameter send with method GET (i.e. in the URL), in PHP you can use a "magic" global named $_GET
(there's also a $_POST
variable, and a $_REQUEST
one, in which both GET and POST params are available).
That being said, that's not possible to give you a server script example that will work with your Javascript without knowing anything about your data source and your data model...
Here the general principle:
<?php
// --- Source data ---
$records = array(
array('id' => 1, 'name' => 'eric', 'age' => 30),
array('id' => 2, 'name' => 'foo', 'age' => 99),
array('id' => 3, 'name' => 'bar', 'age' => 18),
// trailling commas in array are OK in PHP ;)
// let's pretend there's 1000 of them
);
$nRecords = count($records);
// --- Read request params ---
$defaultLimit = 25;
// isset($variable) ensures that the variable exists in order to
// avoid a fatal error
$limit = isset($_GET['limit']) ? $_GET['limit'] : $defaultLimit;
$start = isset($_GET['start']) ? $_GET['start'] : 0;
// --- Construct returned item array ---
$items = array();
for ($i = 0; $i < $limit; $i++) {
$index = $start + $i;
// leave the loop if we've reached the end of the source array
if ($index >= $nRecords) {
break;
}
// or push the record in the item array
else {
$items[] = $records[$index];
}
}
// --- Construct and send the response ---
$responseData = array(
'total' => count($items),
// using the root property you've configured
'items.feed' => $items,
);
// Encode response data to JSON
$jsonData = json_encode($responseData);
// If a callback is specified, the request has been made by a
// JsonP proxy
if (isset($_REQUEST['callback'])) {
$callback = $_REQUEST['callback'];
// HTTP response header
header('Content-Type: text/javascript');
// Encode to JSON
// string concatenation is done with dots in PHP
echo $callback . '(' . $jsonData . ')';
}
// Else we'll return raw json
else {
// HTTP response header
header('Content-Type: application/x-json');
// Encode to JSON and write to output
echo $jsonData;
}
// --- We're done ---
Generally, the start
and limit
params are applied at the DB engine level, in order to save memory on the server side too, and avoid useless processing... I hope you'll be able to adapt from here.
Good luck!