Hopefully I didn't reinvent the wheel here, but I looked around and didn't find a solution. I want to use the DataSourceResult classes with Microsoft SQL Server. When I tried server side paging, it failed. Found that Microsoft added paging support in version 2012, but with a different syntax than other databases. Others use something like "LIMIT x OFFSET y" and MSSQL uses "OFFSET y ROWS FETCH NEXT x ROWS ONLY" for whatever reason. Also, MSSQL won't return results unless you also include a sort column. The Telerik PHP wrapper doesn't seem to account for this.
I found "private function page()" in DataSourceResult.php and had to change it to "protected function page()" so that I can override it, then created this class in my PHP file:
class r2DataSourceResult extends DataSourceResult {
protected function page() {
return ' OFFSET :skip ROWS FETCH NEXT :take ROWS ONLY ';
}
}
That solved half of the problem. I still had to guarantee that there is always a sort column, and I didn't find a way to do that from the grid (which is where I would like it). I could configure the grid to sort by a column by default, but if the user changes the sort to nothing, it breaks. So I added a default sort parameter to the querystring for the data URL that I specify in the grid, and if the grid doesn't pass a sort field via JSON, I add the default field from the querystring like this:
if (!isset($request->sort[0]->field)) {
if (isset($_GET['ds'])) {
$prop = (object) ['field' => $_GET['ds'], 'dir' => 'asc'];
$request->sort = array($prop);
}
else {
echo "Must provide a default sort field with ds querystring parameter.";
}
}
Maybe there's a way to pass a custom value from the grid along with the other JSON request values, but I haven't found that yet. That would be preferable as a method of forcing a default sort column.
So these two tweaks seem to make it work. I've just started, and haven't tried anything other than read functions. Hopefully I'm not going down a rabbit hole here.
Is there already a solution for the new paging syntax with MSSQL 2012 and up, and for forcing a default sort column to always be included in the query?