Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to Paginate please
03/09/2014
13:52
Avatar
coachz
Member
Members
Forum Posts: 11
Member Since:
09/04/2009
sp_UserOfflineSmall Offline

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});


05/09/2014
17:30
Avatar
wexwell
Member
Members
Forum Posts: 10
Member Since:
05/09/2014
sp_UserOfflineSmall Offline

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);
09/09/2014
13:45
Avatar
coachz
Member
Members
Forum Posts: 11
Member Since:
09/04/2009
sp_UserOfflineSmall Offline

I'm sorry but that didn't help me solve my problem.  I have pasted what the server is returning to the grid and what my grid config is.  Why do I not get any pagination or data showing up please ?

09/09/2014
16:46
Avatar
wexwell
Member
Members
Forum Posts: 10
Member Since:
05/09/2014
sp_UserOfflineSmall Offline

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.

12/09/2014
22:12
Avatar
coachz
Member
Members
Forum Posts: 11
Member Since:
09/04/2009
sp_UserOfflineSmall Offline

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/09/2014
13:41
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

 

I recommend you to read this documentation - maybe the whole chapter.

 

Kind Regards

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
29 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information