第一次显示时 有十条数据,刷新 或下一页的时候
却有20条数据 我要的是每次都显示的是每页都显示十条不同的数据,这个却每次都加了十条 之前的数据没有清空!求解。。。。。
服务器代码 import省略
@Component
public class Data extends ActionSupport
{
private Map<String, Object> root;
private List<Add> list = new ArrayList<Add>();
public Map<String, Object> getRoot()
{
return root;
}
@Resource(name = "hashmap")
public void setRoot(Map<String, Object> root)
{
this.root = root;
}
@Override
public String execute() throws Exception
{
Add add = null;
root.put("total",50);
for (int i = 0; i < 10; i++)
{
add = new Add();
add.setCode("code" + i);
add.setName("name" + i);
add.setPrice("price" + i);
list.add(add);
System.out.println("i=" + i);
}
root.put("rows", list);
return SUCCESS;
}
}
jsp
<script type="text/javascript">
var mine;
$(function(){
$('#tt').datagrid({
url:'data.action', rownumbers:true,nowrap:true,pageSize:25,
columns:[[
{field:'code',title:'Code',width:100,editor:"text"},
{field:'name',title:'Name',width:100},
{field:'price',title:'Price',width:100,align:'right',editor:{type:"numberbox"}}
]] ,
onLoadSuccess:function(data){
},
pagination:true,
showFooter:true,
onClickCell:function(rowIndex, field, value){
},onHeaderContextMenu:function(i,field){
alert(i);
alert(field);
},
onClickRow:function(rowIndex){
alert(rowIndex);
}
});
});
$('#tt').datagrid('getPager').pagination({
displayMsg:'当前显示从{from}到{to}共{total}记录',
onBeforeRefresh:function(pageNumber, pageSize){
$(this).pagination('loading');
alert('pageNumber:'+pageNumber+',pageSize:'+pageSize);
$(this).pagination('loaded');
},
});
</script>
</head>
<body>
<table id="tt"></table>
<button onclick="$('#tt').datagrid('loadData',{total:0,rows:[]}");>ddddddddd</button>
</body>
</html>
能贴代码看一下么,你先在url加随机数试试看。
<script type="text/javascript">
var mine;
$(function(){
$('#tt').datagrid({
url:'data.action', rownumbers:true,nowrap:true,pageSize:25,
columns:[[
{field:'code',title:'Code',width:100,editor:"text"},
{field:'name',title:'Name',width:100},
{field:'price',title:'Price',width:100,align:'right',editor:{type:"numberbox"}}
]] ,
onLoadSuccess:function(data){
},
pagination:true,
showFooter:true,
onClickCell:function(rowIndex, field, value){
},onHeaderContextMenu:function(i,field){
alert(i);
alert(field);
},
onClickRow:function(rowIndex){
alert(rowIndex);
}
});
});
$('#tt').datagrid('getPager').pagination({
displayMsg:'当前显示从{from}到{to}共{total}记录',
onBeforeRefresh:function(pageNumber, pageSize){
$(this).pagination('loading');
alert('pageNumber:'+pageNumber+',pageSize:'+pageSize);
$(this).pagination('loaded');
},
});
</script>
</head>
<body>
<table id="tt"></table>
<button onclick="$('#tt').datagrid('loadData',{total:0,rows:[]}");>ddddddddd</button>
</body>
</html>
服务器:
package myshop.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
@Component
public class Data extends ActionSupport
{
private Map<String, Object> root;
private List<Add> list = new ArrayList<Add>();
public Map<String, Object> getRoot()
{
return root;
}
@Resource(name = "hashmap")
public void setRoot(Map<String, Object> root)
{
this.root = root;
}
@Override
public String execute() throws Exception
{
Add add = null;
root.put("total",50);
for (int i = 0; i < 10; i++)
{
add = new Add();
add.setCode("code" + i);
add.setName("name" + i);
add.setPrice("price" + i);
list.add(add);
System.out.println("i=" + i);
}
root.put("rows", list);
return SUCCESS;
}
}
看看那儿错了!!
@小妹子逛街: $(function(){
$('#tt').datagrid({
url:'data.action', rownumbers:true,nowrap:true,pageSize:25,
columns:[[
{field:'code',title:'Code',width:100,editor:"text"},
{field:'name',title:'Name',width:100},
{field:'price',title:'Price',width:100,align:'right',editor:{type:"numberbox"}}
]] ,
onLoadSuccess:function(data){
},
pagination:true,
showFooter:true,
onClickCell:function(rowIndex, field, value){
},onHeaderContextMenu:function(i,field){
alert(i);
alert(field);
},
onClickRow:function(rowIndex){
alert(rowIndex);
}
});
});
grid自带有分页了,你每页设置是显示25条了。
你就用上面这些试试,下面的不用了。
还有官网这个
<tableid="dg"title="Custom DataGrid Pager"style="width:700px;height:250px"
用linq skip().select()
可以看看你传递的后台的参数是多少,第二次,如果错误的话就是前台代码的问题,看看easyUI的案例,改一下就好了,如果是后台代码有问题的话就要看数据访问层的代码了!!