EasyUI Forum
April 23, 2024, 06:42:48 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: datagrid pagination  (Read 8810 times)
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« on: April 18, 2017, 01:24:48 PM »

hello all

I have problems with pagination on datagrid

I put on my retrieve data script the variables $page and $rows like in the demo

Code:
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 50;

$offset = ($page-1)*$rows;

In the query is set limit like:

Code:
...
LIMIT $offset,$rows

The declaration of datagrid is:

Code:
<table id="dg" class="easyui-datagrid" style="width:100%;height:590px;" data-options="
                            singleSelect:true,
                            striped:true,
                            url:'../retrieve/get.php',
                            emptyMsg: 'No data',
                            toolbar:'#tb',
                            sortName:'fbit',
                            sortOrder:'desc',
                            multiSort:false,
                            pagination:true,
                            pagePosition:'bottom',
                            pageSize:50,
                            pageList:[50,100,150,200,250],
                            ..........

The problem is that the datagrid is showing only 50 rows and the pagination said Displaying 1 to 50 of 50 items

and is showing just one page, Page 1 of 1

There are 117 rows in my data base table

Maybe Im missing something?

Please your help, thanks
« Last Edit: April 18, 2017, 01:26:29 PM by catpaw » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: April 18, 2017, 11:31:12 PM »

Please make sure you should return the correct JSON data from your server. The code looks like this:
Code:
echo json_encode(array(
  'total' => ...,
  'rows' => ...,
});
Logged
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« Reply #2 on: April 19, 2017, 06:16:03 AM »

hi sworthy, yes Im secure that the returning properly data, this is my php script:

Code:
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 50;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : ''; 
$order = isset($_POST['order']) ? strval($_POST['order']) : '';
$offset = ($page-1)*$rows;

$q = isset($_REQUEST['q']) ? mysql_real_escape_string($_REQUEST['q']) : '';

$result = array();

$sql = "SELECT * FROM mytable WHERE field like '%$q%' ORDER BY $sort $order LIMIT $offset,$rows";

$rs = mysql_query($sql);

$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}

$result["total"] = count($items);
$result["rows"] = $items;

echo json_encode($result);
But I think I know where is the problem now, I need do the same query with the count without LIMIT  Roll Eyes
Logged
qianet
Newbie
*
Posts: 9


View Profile Email
« Reply #3 on: June 13, 2017, 01:04:38 PM »

1. total=...select count(0) from ... where ...filed like '%...%' order by filed asc ===> 113
2. rows= ..select * from ... where ...filed like '%...%' and rowid between 0 to 49 order by filed asc ==>50
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!