用xml做数据源,但是排序和分页都没有反应。server.xml是静态的文件。
我用json也使了,把查出来的数据都组合成jsonstring排序和分页还是没有反应用的是jqgrid3.4.3
example.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jqGrid Demo</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow: auto; /* Remove scroll bars on browser window */
font: 12px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana;
}
</style><link rel="stylesheet" type="text/css" media="screen" href="themes/coffee/grid.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.jqGrid.js" type="text/javascript"></script><script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list2").jqGrid({
url: 'server.xml',
datatype: "xml",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
pager: jQuery('#pager2'),
rowNum:10,
rowList:[10,20,30],
imgpath: 'themes/sand/images',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "Demo",
});
});
</script>
</head>
<body>
<table id="list2" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager2" class="scroll" style="text-align:center;"></div>
</body>
</html>
server.xml
<?xml version="1.0" encoding="utf-8" ?>
<rows>
<page>1</page>
<total>15</total>
<records>10</records>
<row id='1'>
<cell>3</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='2'>
<cell>4</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='3'>
<cell>5</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='4'>
<cell>6</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='5'>
<cell>7</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='6'>
<cell>8</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='7'>
<cell>9</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='8'>
<cell>10</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
...
</rows>还想问一下:分页是jqgrid做好的呢,还是通过传当前页,然后从后台查询重新生成json进行绑定?
我用json也使了,把查出来的数据都组合成jsonstring排序和分页还是没有反应用的是jqgrid3.4.3
example.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jqGrid Demo</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow: auto; /* Remove scroll bars on browser window */
font: 12px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana;
}
</style><link rel="stylesheet" type="text/css" media="screen" href="themes/coffee/grid.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.jqGrid.js" type="text/javascript"></script><script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list2").jqGrid({
url: 'server.xml',
datatype: "xml",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
pager: jQuery('#pager2'),
rowNum:10,
rowList:[10,20,30],
imgpath: 'themes/sand/images',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "Demo",
});
});
</script>
</head>
<body>
<table id="list2" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager2" class="scroll" style="text-align:center;"></div>
</body>
</html>
server.xml
<?xml version="1.0" encoding="utf-8" ?>
<rows>
<page>1</page>
<total>15</total>
<records>10</records>
<row id='1'>
<cell>3</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='2'>
<cell>4</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='3'>
<cell>5</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='4'>
<cell>6</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='5'>
<cell>7</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='6'>
<cell>8</cell>
<cell>31</cell>
<cell>32</cell>
<cell>33</cell>
<cell>34</cell>
<cell>35</cell>
<cell>36</cell>
</row>
<row id='7'>
<cell>9</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
<row id='8'>
<cell>10</cell>
<cell>41</cell>
<cell>42</cell>
<cell>43</cell>
<cell>44</cell>
<cell>45</cell>
<cell>46</cell>
</row>
...
</rows>还想问一下:分页是jqgrid做好的呢,还是通过传当前页,然后从后台查询重新生成json进行绑定?
终于弄明白了。
排序和分页得在生成数据源页面的后台进行操作,读取当前页,排序字段,排序规则。
我的是asp.net的。后台要读取
string sort = Request.Params["sidx"]; //排序字段
string page = Request.Params["page"]; //当前页
string rows = Request.Params["rows"]; //总行数
string sord = Request.Params["sord"]; //排序方式
sidx,page,rows,sord不用变,这个事jqgrid默认写的。然后进行排序。
分页:每次读取固定记录,然后生成json.就可以了。也许大家对这种小问题都解决了,记录下来给需要的人。
我的信箱:[email protected] 非常感谢
邮箱:[email protected] 谢谢