-
Notifications
You must be signed in to change notification settings - Fork 0
/
37scroll.html
100 lines (92 loc) · 2.64 KB
/
37scroll.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<div style="font-size:12px;">
We can make a virtual scroll to a relative big local data - i.e scroll option set to 1 <br>
<br>
</div>
<br />
<table id="scroll37"></table>
<div id="pscroll37" ></div>
<script src="37scroll.js" type="text/javascript"> </script>
<br />
<div style="font-size:12px;">
<b> HTML </b>
<XMP>
...
<table id="scroll37"></table>
<div id="pscroll37" ></div>
</XMP>
<b>Java Scrpt code</b>
<XMP>
...
jQuery("#scroll37").jqGrid({
url:'localset.php',
datatype: "json",
height: 255,
width: 600,
colNames:['Index','Name', 'Code'],
colModel:[
{name:'item_id',index:'item_id', width:65, sorttype:'int'},
{name:'item',index:'item', width:150},
{name:'item_cd',index:'item_cd', width:100}
],
rowNum:50,
rowTotal: 2000,
rowList : [20,30,50],
scroll:1,
loadonce:true,
mtype: "GET",
rownumbers: true,
rownumWidth: 40,
gridview: true,
pager: '#pscroll37',
sortname: 'item_id',
viewrecords: true,
sortorder: "asc",
caption: "Virtual scrolling on local data"
});
jQuery("#scroll37").jqGrid('navGrid','#pscroll37',{del:false,add:false,edit:false},{},{},{},{multipleSearch:true});
</XMP>
<b>PHP with MySQL</b>
<XMP>
...
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
$totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
if($totalrows) {
$limit = $totalrows;
}
// connect to the database
$db = mysql_pconnect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error conecting to db.");
//populateDBRandom();
$result = mysql_query("SELECT COUNT(*) AS count FROM items");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
if ($limit<0) $limit = 0;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT item_id, item, item_cd FROM items ".$where." ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn’t execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[item_id];
$responce->rows[$i]['cell']=array($row[item_id],$row[item],$row[item_cd]);
$i++;
}
echo json_encode($responce);
mysql_close($db);
...
</XMP>
</div>