Forum
Topic RSS
13:52
09/04/2009
OfflineHow 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
OfflineMine 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
OfflineThis 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
OfflineI 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
OfflineFor 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: 816
Currently Online:
33 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
Log In
Home