jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Grid Pagination with laravel 4
This topic contains 3 replies, has 2 voices, and was last updated by Peter Stoev 10 years, 12 months ago.
-
Author
-
My jQgrid is working fine except the paging property .. i am using laravel 4 for server side coding .. and followed the doc here ..
I have 16 records in db … and at first it is gettng 10 items from db as the default property of pagesize is 10 but in total it shoud echo 16 .. but it isn’t .. but the property in my json data ‘TotalRows’ is 16 but the next page with 6 records is not showing ..
here is my code
$(document).ready(function () { var url = 'http://laravelapp/diamonds/mydata'; // prepare the data var source = { datatype: "json", datafields: [ { name: 'id', type: 'string' }, { name: 'owner', type: 'string' }, { name: 'shape', type: 'string' }, { name: 'color', type: 'string' }, { name: 'carat', type: 'string' }, { name: 'clarity', type: 'string' }, { name: 'price', type: 'string' }, { name: 'certificate', type: 'string' }, { name: 'depth', type: 'string' }, { name: 'tablePercent', type: 'string' }, { name: 'polish', type: 'string' }, { name: 'symmetry', type: 'string' }, { name: 'fluorescence', type: 'string' }, { name: 'measurement', type: 'string' }, { name: 'stockno', type: 'string' }, { name: 'ratio', type: 'string' }, { name: 'cut', type: 'string' }, { name: 'pricePerCarat', type: 'string' }, ], cache : false, url: url, root: 'Rows', //beforeprocessing: function (data) { // source.totalrecords = data[0].TotalRows; //} }; var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxgrid").jqxGrid( { width: 950, height: 350, source: dataAdapter, //autoheight: true, pageable: true, //pagermode: 'simple', //pagesize: 5, columns: [ { text: 'ID', datafield: 'id', width: 70 }, { text: 'OWNER', datafield: 'owner', width: 100 }, { text: 'SHAPE', datafield: 'shape', width: 60 }, { text: 'COLOR', datafield: 'color', width: 40 }, { text: 'CLARITY', datafield: 'clarity', width: 50 }, { text: 'PRICE', datafield: 'price', width: 60 }, { text: 'CERT', datafield: 'certificate', width: 40 }, { text: 'UserName', datafield: 'depth', width: 50 }, { text: 'TABLE', datafield: 'tablePercent', width: 60 }, { text: 'UserName', datafield: 'polish', width: 50 }, { text: 'SYM', datafield: 'symmetry', width: 60 }, { text: 'FLOUR', datafield: 'fluorescence', width: 40 }, { text: 'UserName', datafield: 'measurement', width: 50 }, { text: 'RATIO', datafield: 'ratio', width: 60 }, { text: 'CUT', datafield: 'cut', width: 40 }, { text: 'Price/CRT', datafield: 'pricePerCarat', width: 60 }, ] }); });
and here is my laravel controller code ..
public function mydata() { $pagenum = Input::get('pagenum'); $pagesize = Input::get('pagesize'); $start = $pagenum * $pagesize; // logic for color filter $color = ''; if(Session::has('colorMin') && Session::has('colorMax')) { $colors = array('A','B','C','D', 'E', 'F', 'G', 'H', 'I', 'J'); $colorMin = Session::get('colorMin'); $colorMax = Session::get('colorMax'); for($i = $colorMin; $i <= $colorMax; $i++) $color .= "'".$colors[$i]."',"; $color = substr($color, 0 , (strlen($color)-1)); }else{ $color .= "'A','B','C','D', 'E', 'F', 'G', 'H', 'I', 'J'"; } //var_dump($color); $myData = Diamond::whereRaw("color in (".$color.") limit ". $start.",".$pagesize."")->get(); $myDataCount = Diamond::whereRaw("color in (".$color.") limit ". $start.",".$pagesize."")->count(); $data[] = array( 'TotalRows' => $myDataCount, 'Rows' => $myData->toArray() ); //return View::make('diamonds.data')->with('mydata', $mydata); return json_encode($data); }
Hi fahim74,
As far as I see, you want to implement server paging with jqxGrid. In order to achieve that, please look at: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/serverpaging.htm?arctic and http://www.jqwidgets.com/jquery-widgets-documentation/documentation/phpintegration/php-server-side-grid-paging.htm
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Thx for the Reply .. I have followed the source code of that Demo Grid page and now its working fine .. only thing that is missing was this line ..
rendergridrows: function(){ return dataAdapter.records; },
But in the doc specified here .. it is .. that doesn’t work
http://www.jqwidgets.com/jquery-widgets-documentation/documentation/phpintegration/php-server-side-grid-paging.htmrendergridrows: function (params) { return params.data; },
I think if updating the doc with the code should fix the future problem with Grid Paging .
Hi fahim74,
Actually, params.data is fine as well. We have working demo with it here: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/serverfiltering_paging_and_sorting.htm?arctic
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.