Forum
13:52
09/04/2009
How can I get my data grid to paginate and show data please?  My laravel controller sends back the following for pagination and below is my jqgrid config. I have tried prmNames but I must be doing something wrong. When I don't use pagination and just send back data, it jqgrid displays the data but when I send pagination and data I get no data displayed and no pagination. Thanks for any help.
{ Â "total": 91, Â "per_page": 10, Â "current_page": 1, Â "last_page": 10, Â "from": 1, Â "to": 10, Â "data": [ Â Â Â { Â Â Â Â Â "id": "ALFKI", Â Â Â Â Â "CompanyName": "Alfreds Futterkiste", Â Â Â Â Â "ContactName": "Maria Anders" Â Â Â }, Â Â Â { Â Â Â Â Â "id": "ANATR", Â Â Â Â Â "CompanyName": "Ana Trujillo Emparedados y helados", Â Â Â Â Â "ContactName": "Ana Trujillo" Â Â Â } Â Â Â } ] jqgrid code......... <div class="container"> Â Â Â Â Â Â <span class="label label-default">My Grid</span> Â Â Â Â Â Â <br /><br /> Â Â Â Â Â Â <table id="list"><tr><td></td></tr></table> Â Â Â Â Â Â <div id="pager"></div> Â Â Â </div> Â $("#list").jqGrid({ Â Â Â Â Â Â Â Â Â Â Â Â Â url: "customersData", Â Â Â Â Â Â Â Â Â Â Â Â Â datatype: "json", Â Â Â Â Â Â Â Â Â Â Â Â Â mtype: "GET", Â Â Â Â Â Â Â Â Â Â Â Â Â prmNames: {page: "current_page", rows: "per_page"}, Â Â Â Â Â Â Â Â Â Â Â Â Â //prmNames: {page: "pageIndex", sort: "sortCol", order: "sortDir", rows: "pageSize"}, Â Â Â Â Â Â Â Â Â Â Â Â Â colNames:['Unique Id', 'CompanyName', 'ContactName'], Â Â Â Â Â Â Â Â Â Â Â Â Â colModel: [ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { name: "id", width: 55 }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { name: "CompanyName", width: 55 }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { name: "ContactName", width: 55 } Â Â Â Â Â Â Â Â Â Â Â Â Â ], Â Â Â Â Â Â Â Â Â Â Â Â Â pager: "#pager", Â Â Â Â Â Â Â Â Â Â Â Â Â rowNum: 3, Â Â Â Â Â Â Â Â Â Â Â Â Â rowList: [10, 20, 30], Â Â Â Â Â Â Â Â Â Â Â Â Â //width: 600, Â Â Â Â Â Â Â Â Â Â Â Â Â autowidth: true, Â Â Â Â Â Â Â Â Â Â Â Â Â height: "100%", Â Â Â Â Â Â Â Â Â Â Â Â Â sortname: "CompanyName", Â Â Â Â Â Â Â Â Â Â Â Â Â sortorder: "desc", Â Â Â Â Â Â Â Â Â Â Â Â Â viewrecords: true, Â Â Â Â Â Â Â Â Â Â Â Â Â gridview: true, Â Â Â Â Â Â Â Â Â Â Â Â // autoencode: true, Â Â Â Â Â Â Â Â Â Â Â Â Â caption: "My first grid" Â Â Â Â Â Â Â Â Â }); Â Â Â Â Â Â Â Â Â $("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true});
17:30
05/09/2014
Mine works fine and this is what I am sending back (and how I am sending it). I doubt my queries will do much good, I'm using mssql.
Â
$page = $_POST['page']; $rows = $_POST['rows']; $data['records']=$rowcnt; $data['page']=$page; $data['total']=$rowcnt/$rows; $data['rows']=$result; //this is the data set from the query echo json_encode($data);
16:46
05/09/2014
This is what you are returning with your code;
"total": 91, Â "per_page": 10, Â "current_page": 1, Â "last_page": 10, Â "from": 1, Â "to": 10, Â "data": [
Â
If you would have actually compared to what I was sending you would have noticed your parameters are not set correctly for pagination to work. One example - total is the total number of pages (the way I set it), you are setting it to the total number of records. The parameter I am setting (note - I didn't simply name my own I set them according to the documentation) for the current page is simply 'page', you are using current_page. If you analyze and adapt what I posted, or read the documentation on naming conventions, you should have no problem getting it to work.
22:12
09/04/2009
I had to write the entire paginator.......
   // coming in from jqGrid
      Log::info(Input::all());
         // array (
         //  '_search' => 'false',         // search enabled
         //  'nd' => '1410449702065',
         //  'per_page' => '10',
         //  'current_page' => '1',
         //  'sidx' => 'CompanyName',
         //  'sord' => 'desc',
         // )
      $page = Input::get("page", 1);   // get the requested page
      $limit = Input::get("rows"); // get how many rows we want to have into the grid
      $sidx = Input::get("sidx", 1); // get index row - i.e. user click to sort
      $sord = Input::get("sord", "asc"); // get the direction
        if (!$limit) $limit = 25;
      $count = DB::table('customers')->count();
     Â
      // calculate the total pages for the query
      if( $count > 0 && $limit > 0) {
          $count = ceil($count/$limit);
      } else {
          $count = 0;
      }
     Â
      // if for some reasons the requested page is greater than the total
       // set the requested page to total page
      if ($page > $count) $page=$count;
      // calculate the starting position of the rows
        $start = $limit * $page - $limit; // do not put $limit*($page - 1)
      // if for some reasons start position is negative set it to 0
        // typical case is that the user type 0 for the requested page
        if($start <0) $start = 0;
        Log::info($sidx . "|" . $sord . "|" . $limit . "|" . $start);
      $results = DB::table('customers')->orderBy($sidx, $sord)->take($limit)->skip($start)->get();
     Â
      Log::info($results);
      //$paginationResults = Paginator::make( $rows, $count, $page);
         //$items - record set of query result
         //$total - number of records into fetch result
         //$per_page - number of records per page you want
      //$results = Customer::all();
      //$arr = ["page" => 1, "records" => 4, 'total'=> 2, 'rows' => $results];
      $arr = ["page" => $page, "records" => $limit, 'total'=> $count, 'rows' => $results];
      //return Response::json($arr);
      return Response::json($arr);
13:41
Moderators
30/10/2007
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
41 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66