代码如下:
问题:
例如:在jqgrid有分页的情况下,选择非第一页时(比如第2页的某个列),对列进行排序,jqgrid回传的url的当前页码会变成是第一页而非我当前选择的第二页,如何解决?
$("#selectinfo").show();
var times,url,bt,cl,tp;
times = new Date().getTime();
url="/ServletBase.ashx?";
jQuery("#list2").trigger("reloadGrid");
jQuery("#list2").jqGrid({
url:url,
datatype: "xml",
mtype: 'GET',
width:document.body.clientWidth,
colNames:['片区编号','片区名称', '状态', '备注','操作'],
colModel:[
{name:'areaid',index:'areaid',align:'center'},
{name:'areaname',index:'areaname',align:'center'},
{name:'status',index:'status',align:'center',formatter:'checkbox'},
{name:'note',index:'note',align:'center'},
{name:'operator',index:'operator',align:'center',width:120,sortable:false}
],
rowNum:2,
pager: $('#pager2'),
sortname: '片区编号',
viewrecords: true,
sortname:"areaid",
sortorder: "asc",
pginput:true,
caption:"",
sortable: true,
drag: true,
gridview: true,
rownumbers: true,
rownumWidth: 50,
multiselect: false,
loadComplete: function()
{
var ids = jQuery("#list2").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++)
{
cl = ids[i];
tp =$("#list2").getCell(cl,3);
bt="<input type='button' value='编辑' id='edit"+cl+"' />";
if (tp.toUpperCase()=="yes".toUpperCase())
{
bt+="<input type='button' value='禁用' id='status"+cl+"'onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
else
{
bt+="<input type='button' value='启用' id='status"+cl+"' onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
jQuery("#list2").jqGrid('setRowData',ids[i],{operator:bt});
}
},
onSortCol: function (index, colindex, sortorder)
{
//列排序事件
alert('onSortCol index=>'+index +" colindex=>"+colindex +" sortorder=>"+sortorder); },
loadError : function(xhr,st,err)
{
alert("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
//$("#tblMasterMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
} });
$("#list2").resetSelection();
问题:
例如:在jqgrid有分页的情况下,选择非第一页时(比如第2页的某个列),对列进行排序,jqgrid回传的url的当前页码会变成是第一页而非我当前选择的第二页,如何解决?
$("#selectinfo").show();
var times,url,bt,cl,tp;
times = new Date().getTime();
url="/ServletBase.ashx?";
jQuery("#list2").trigger("reloadGrid");
jQuery("#list2").jqGrid({
url:url,
datatype: "xml",
mtype: 'GET',
width:document.body.clientWidth,
colNames:['片区编号','片区名称', '状态', '备注','操作'],
colModel:[
{name:'areaid',index:'areaid',align:'center'},
{name:'areaname',index:'areaname',align:'center'},
{name:'status',index:'status',align:'center',formatter:'checkbox'},
{name:'note',index:'note',align:'center'},
{name:'operator',index:'operator',align:'center',width:120,sortable:false}
],
rowNum:2,
pager: $('#pager2'),
sortname: '片区编号',
viewrecords: true,
sortname:"areaid",
sortorder: "asc",
pginput:true,
caption:"",
sortable: true,
drag: true,
gridview: true,
rownumbers: true,
rownumWidth: 50,
multiselect: false,
loadComplete: function()
{
var ids = jQuery("#list2").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++)
{
cl = ids[i];
tp =$("#list2").getCell(cl,3);
bt="<input type='button' value='编辑' id='edit"+cl+"' />";
if (tp.toUpperCase()=="yes".toUpperCase())
{
bt+="<input type='button' value='禁用' id='status"+cl+"'onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
else
{
bt+="<input type='button' value='启用' id='status"+cl+"' onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
jQuery("#list2").jqGrid('setRowData',ids[i],{operator:bt});
}
},
onSortCol: function (index, colindex, sortorder)
{
//列排序事件
alert('onSortCol index=>'+index +" colindex=>"+colindex +" sortorder=>"+sortorder); },
loadError : function(xhr,st,err)
{
alert("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
//$("#tblMasterMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
} });
$("#list2").resetSelection();
解决方案 »
- 新年快乐,分享一个我写了1年的IM源码,谁要?可能有人听说过我写的“旺旺通”
- 寻求高人,优化这段JavaScript代码
- JAVAScript与Flash冲突
- javascript定时关闭对话框的问题
- 一个纯粹送分的问题哈 各位帮帮忙
- 梯形的区域,Y轴还和其他区域有交集,询问如何各自触发鼠标滑过和点击的时间
- 如何在IFRAME里得到父窗口的全局变量的值?
- excel.application的问题。
- 在文本框中输入数字后,按下回车实现页面跳转,有什么事件?在线等待。。。。
- 打开一个视频文件asf格式的(不是带视频的网页!!)怎样才能相应的弹出一个网页,重分!!
- 去网页游戏开发公司面试时,js要了解那些方面的呀?
- 关于sort()函数
有时候客户要求的就是希望实现当前按照指定列客户端排序的效果(所以不希望返回第一页)。
$("#selectinfo").show();
var times,url,bt,cl,tp;
times = new Date().getTime();
url="/ServletBase.ashx?";
url=url+"action=findarealist&logtime="+encodeURI(times)+"&areaid="+encodeURI($("#areaid").val())+"&areaname="+encodeURI($("#areaname").val())+"&status="+encodeURI($("#Status").val());
jQuery("#list2").trigger("reloadGrid");
jQuery("#list2").jqGrid({
url:url,
datatype: "xml",
mtype: 'GET',
width:document.body.clientWidth,
colNames:['片区编号','片区名称', '状态', '备注','操作'],
colModel:[
{name:'areaid',index:'areaid',align:'center',sortable:false},
{name:'areaname',index:'areaname',align:'center',sortable:true},
{name:'status',index:'status',align:'center',formatter:'checkbox',sortable:false},
{name:'note',index:'note',align:'center',sortable:false},
{name:'operator',index:'operator',align:'center',width:120,sortable:false}
],
rowNum:2,
pager: $('#pager2'),
sortname: '片区编号',
viewrecords: true,
sortname:"areaid",
sortorder: "asc",
pginput:true,
caption:"",
sortable: true,
drag: true,
gridview: true,
rownumbers: true,
rownumWidth: 50,
multiselect: false,
loadComplete: function()
{
var ids = jQuery("#list2").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++)
{
cl = ids[i];
tp =$("#list2").getCell(cl,3);
bt="<input type='button' value='编辑' id='edit"+cl+"' />";
if (tp.toUpperCase()=="yes".toUpperCase())
{
bt+="<input type='button' value='禁用' id='status"+cl+"'onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
else
{
bt+="<input type='button' value='启用' id='status"+cl+"' onclick=\"editstatus('"+$("#list2").getCell(cl,1)+"','"+tp+"','"+cl+"')\" />";
}
jQuery("#list2").jqGrid('setRowData',ids[i],{operator:bt});
}
},
onSortCol: function (index, colindex, sortorder)
{
//列排序事件
alert('onSortCol index=>'+index +" colindex=>"+colindex +" sortorder=>"+sortorder); },
loadError : function(xhr,st,err)
{
alert("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
//$("#tblMasterMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
onHeaderClick:function()
{
alert("111");
} });
通过
onPaging:function()
{
dd=jQuery('#list2').jqGrid('getGridParam','page');
}
onSortCol: function (index, colindex, sortorder)
{
//列排序事件
jQuery("#list2").jqGrid('setGridParam',{page:dd});
}