jqgrid学习.docx
《jqgrid学习.docx》由会员分享,可在线阅读,更多相关《jqgrid学习.docx(18页珍藏版)》请在冰豆网上搜索。
jqgrid学习
一、主要API接口getGridParam、setGridParam:
getGridParam方法:
getGridParam("url"):
获取当前的AJAX的URL
getGridParam("sortname"):
排序的字段
getGridParam("sortorder"):
排序的顺序
getGridParam("selrow"):
得到选中行的ID
getGridParam("page"):
当前的页数
getGridParam("rowNum"):
当前有多少行
getGridParam("datatype"):
得到当前的datatype
getGridParam("records"):
得到总记录数
getGridParam("selarrrow"):
可以多选时,返回选中行的ID
setGridParam方法:
setGridParam({url:
newvalue}):
可以设置一个grid的ajaxurl,可配合trigger("reloadGrid")使用
setGridParam({sortname:
设置排序的字段
setGridParam({sortorder:
设置排序的顺序ascordesc
setGridParam({page:
设置翻到第几页
setGridParam({rowNum:
设置当前每页显示的行数
setGridParam({datatype:
设置新的datatype(xml,json)
形式2:
jQuery('#tableID').jqGrid('getGridParam','url'))
jQuery("#tableID").jqGrid('setGridParam',{page:
2}).trigger("reloadGrid")
二、jqGridcolModel表体结构配置
name 必要的属性,具有唯一标识性,如在弹出的editform窗体中,将作为input的name属性index为排序用,最方便的是设为数据库字段width150,宽度,数值alignleft,center,rightdetefmtdate:
trueeditableflaseeditoptionsedittype为先决条件,此为值,[]editrules编辑规范edittypetext,textarea,select,checkbox,passwordformatoptionsformatterhidedlgfalse(appearinthemodaldialog)hiddenfalse在加载时是否隐藏列jsonmap声明json的格式keyfalselabel当没有设置colNames时,在列里用此代替,此项也为空时,就是name代替resizabletrue,列宽可调节searchtrue,可搜索sortabletrue,可排序sorttypetext,int,float,date,排序子段类型xmlmap声明xml的格式
三、一个例子[ArrayData]
//
jQuery("#list4").jqGrid({
datatype:
"local",
height:
250,
colNames:
['InvNo','Date','Client','Amount','Tax','Total','Notes'],
colModel:
[
{name:
'id',index:
'id',width:
60,sorttype:
"int"},
'invdate',index:
'invdate',width:
90,sorttype:
"date"},
'name',index:
'name',width:
100},
'amount',index:
'amount',width:
80,align:
"right",sorttype:
"float"},
'tax',index:
'tax',width:
'total',index:
'total',width:
'note',index:
'note',width:
150,sortable:
false}
],
multiselect:
true,
caption:
"ManipulatingArrayData"
});
varmydata=[
{id:
"1",invdate:
"2007-10-01",name:
"test",note:
"note",amount:
"200.00",tax:
"10.00",total:
"210.00"},
"2",invdate:
"2007-10-02",name:
"test2",note:
"note2",amount:
"300.00",tax:
"20.00",total:
"320.00"},
"3",invdate:
"2007-09-01",name:
"test3",note:
"note3",amount:
"400.00",tax:
"30.00",total:
"430.00"},
"4",invdate:
"2007-10-04",name:
"5",invdate:
"2007-10-05",name:
"6",invdate:
"2007-09-06",name:
"7",invdate:
"8",invdate:
"2007-10-03",name:
"9",invdate:
"430.00"}
];
for(vari=0;i<=mydata.length;i++)
jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
四、行操作
//获取选中行数据
jQuery("#a1").click(function(){
varid=jQuery("#list5").jqGrid('getGridParam','selrow');
if(id){
varret=jQuery("#list5").jqGrid('getRowData',id);
alert("id="+ret.id+"invdate="+ret.invdate+"...");
}else{alert("请选择一行!
");}
//删除
jQuery("#a2").click(function(){
varsu=jQuery("#list5").jqGrid('delRowData',12);
if(su)alert("成功删除第12行");elsealert("删除失败");
//更新
jQuery("#a3").click(function(){
varsu=jQuery("#list5").jqGrid('setRowData',11,{amount:
"333.00",tax:
"33.00",total:
"366.00",note:
""});
if(su)alert("更新成功");elsealert("更新失败");
//新增
jQuery("#a4").click(function(){
vardatarow={id:
"99",invdate:
"430.00"};
varsu=jQuery("#list5").jqGrid('addRowData',99,datarow);
if(su)alert("新增成功");elsealert("新增失败");
五、进阶
多选
HTML
...
void(0)"id="m1">GetSelectedid'svoid(0)"id="m1s">Select(Unselect)row13JavaScrptcode...jQuery("#list9").jqGrid({url:'server.php?q=2&nd='+newDate().getTime(),datatype:"json",colNames:['InvNo','Date','Client','Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',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}],rowNum:10,rowList:[10,20,30],pager:'#pager9',sortname:'id',recordpos:'left',viewrecords:true,sortorder:"desc",multiselect:true,caption:"MultiSelectExample"});jQuery("#list9").jqGrid('navGrid','#pager9',{add:false,del:false,edit:false,position:'right'});jQuery("#m1").click(function(){vars;s=jQuery("#list9").jqGrid('getGridParam','selarrrow');alert(s);});jQuery("#m1s").click(function(){jQuery("#list9").jqGrid('setSelection',"13");});主从表HTML...InvoiceHeader
void(0)"id="m1">GetSelectedid's
void(0)"id="m1s">Select(Unselect)row13JavaScrptcode...jQuery("#list9").jqGrid({url:'server.php?q=2&nd='+newDate().getTime(),datatype:"json",colNames:['InvNo','Date','Client','Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',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}],rowNum:10,rowList:[10,20,30],pager:'#pager9',sortname:'id',recordpos:'left',viewrecords:true,sortorder:"desc",multiselect:true,caption:"MultiSelectExample"});jQuery("#list9").jqGrid('navGrid','#pager9',{add:false,del:false,edit:false,position:'right'});jQuery("#m1").click(function(){vars;s=jQuery("#list9").jqGrid('getGridParam','selarrrow');alert(s);});jQuery("#m1s").click(function(){jQuery("#list9").jqGrid('setSelection',"13");});主从表HTML...InvoiceHeader
void(0)"id="m1s">Select(Unselect)row13
JavaScrptcode
jQuery("#list9").jqGrid({
url:
'server.php?
q=2&nd='+newDate().getTime(),
"json",
55},
90},
"right"},
rowNum:
10,
rowList:
[10,20,30],
pager:
'#pager9',
sortname:
'id',
recordpos:
'left',
viewrecords:
sortorder:
"desc",
"MultiSelectExample"
jQuery("#list9").jqGrid('navGrid','#pager9',{add:
false,del:
false,edit:
false,position:
'right'});
jQuery("#m1").click(function(){
vars;
s=jQuery("#list9").jqGrid('getGridParam','selarrrow');
alert(s);
jQuery("#m1s").click(function(){
jQuery("#list9").jqGrid('setSelection',"13");
主从表
InvoiceHeader
InvoiceDetail
void(0)"id="ms1">GetSelectedid'sJavaScrptcode...jQuery("#list10").jqGrid({url:'server.php?q=2',datatype:"json",colNames:['InvNo','Date','Client','Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',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}],rowNum:10,rowList:[10,20,30],pager:'#pager10',sortname:'id',viewrecords:true,sortorder:"desc",multiselect:false,caption:"InvoiceHeader",onSelectRow:function(ids){if(ids==null){ids=0;if(jQuery("#list10_d").jqGrid('getGridParam','records')>0){jQuery("#list10_d").jqGrid('setGridParam',{url:"subgrid.php?q=1&id="+ids,page:1});jQuery("#list10_d").jqGrid('setCaption',"InvoiceDetail:"+ids).trigger('reloadGrid');}}else{jQuery("#list10_d").jqGrid('setGridParam',{url:"subgrid.php?q=1&id="+ids,page:1});jQuery("#list10_d").jqGrid('setCaption',"InvoiceDetail:"+ids).trigger('reloadGrid');}}});jQuery("#list10").jqGrid('navGrid','#pager10',{add:false,edit:false,del:false});jQuery("#list10_d").jqGrid({height:100,url:'subgrid.php?q=1&id=0',datatype:"json",colNames:['No','Item','Qty','Unit','LineTotal'],colModel:[{name:'num',index:'num',width:55},{name:'item',index:'item',width:180},{name:'qty',index:'qty',width:80,align:"right"},{name:'unit',index:'unit',width:80,align:"right"},{name:'linetotal',index:'linetotal',width:80,align:"right",sortable:false,search:false}],rowNum:5,rowList:[5,10,20],pager:'#pager10_d',sortname:'item',viewrecords:true,sortorder:"asc",multiselect:true,caption:"InvoiceDetail"}).navGrid('#pager10_d',{add:false,edit:false,del:false});jQuery("#ms1").click(function(){vars;s=jQuery("#list10_d").jqGrid('getGridParam','selarrrow');alert(s);});可展开的下级表HTML...<JavaScrptcode...jQuery("#list11").jqGrid({url:'server.php?q=1',datatype:"xml",height:200,colNames:['InvNo','Date','Client','Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',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}],rowNum:10,rowList:[10,20,30],pager:'#pager11',sortname:'id',viewrecords:true,sortorder:"desc",multiselect:false,subGrid:true,subGridUrl:'subgrid.php?q=2',subGridModel:[{name:['No','Item','Qty','Unit','LineTotal'],width:[55,200,80,80,80]}],caption:"SubgridExample"});jQuery("#list11").jqGrid('navGrid','#pager11',{add:false,edit:false,del:false});壳展开的下级表2HTML...JavaScrptcodejQuery("#listsg11").jqGrid({url:'server.php?q=1',datatype:"xml",height:190,colNames:['InvNo','Date','Client','Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',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}],rowNum:8,rowList:[8,10,20,30],pager:'#pagersg11',sortname:'id',viewrecords:true,sortorder:"desc",multiselect:false,subGrid:true,caption:"GridasSubgrid",subGridRowExpanded:function(subgrid_id,row_id){//wepasstwoparameters//subgrid_idisaidofthedivtagcreatedwhitinatabledata//theidofthiselemenetisacombinationofthe"sg_"+idoftherow//therow_idistheidoftherow//Ifwewantopassadditinalparameterstotheurlwecanuse//amethodgetRowData(row_id)-whichreturnsassociativearrayintypename-value//herewecaneasyconstructtheflowingvarsubgrid_table_id,pager_id;subgrid_table_id=subgrid_id+"_t";pager_id="p_"+subgrid_table_id;$("#"+subgrid_id).html( 展开阅读全文 相关资源 大学课件《高分子物理》教案..pptx 图形创意设计-想象.ppt 绿色大气简约端午活动策划动态PPT模板.pptx 简洁创意二十届三中全会要点解读PPT深入学习贯彻三中全会精神党课课件.pptx 技能培训资料:常用水泵大总结.docx 2023年住建局工作总结分析(5篇).docx 2021-2022学年四川省成都市高一上英语期末考试题.docx 复方丹参片前处理及提取生产工规程.doc 华中科技大学谭毅华数据挖掘分类.pptx 固定污染源烟气排放连续监测系统.ppt 猜你喜欢 煤矿各工种59个考试题库大全.docx 煤矿团委工作报告及工作计划.docx 苏教版四年级上册数学教案第35单元.docx 美容小知识.docx 秘书工作自我鉴定7篇.docx 碳关税对国内高碳产业影响.docx 淘小铺开店创业原来真的很简单.docx 面试个人简历表.docx 提炼观点练习之欧阳文创编.docx 相关搜索 jqgrid 学习 当前位置:首页 > 幼儿教育 > 唐诗宋词
void(0)"id="ms1">GetSelectedid's
jQuery("#list10").jqGrid({
q=2',
'#pager10',
false,
"InvoiceHeader",
onSelectRow:
function(ids){
if(ids==null){
ids=0;
if(jQuery("#list10_d").jqGrid('getGridParam','records')>0)
{
jQuery("#list10_d").jqGrid('setGridParam',{url:
"subgrid.php?
q=1&id="+ids,page:
1});
jQuery("#list10_d").jqGrid('setCaption',"InvoiceDetail:
"+ids)
.trigger('reloadGrid');
}
}else{
jQuery("#list10").jqGrid('navGrid','#pager10',{add:
false});
jQuery("#list10_d").jqGrid({
100,
'subgrid.php?
q=1&id=0',
['No','Item','Qty','Unit','LineTotal'],
'num',index:
'num',width:
'item',index:
'item',width:
180},
'qty',index:
'qty',width:
'unit',index:
'unit',width:
'linetotal',index:
'linetotal',width:
"right",sortable:
false,search:
5,
[5,10,20],
'#pager10_d',
'item',
"asc",
"InvoiceDetail"
}).navGrid('#pager10_d',{add:
jQuery("#ms1").click(function(){
s=jQuery("#list10_d").jqGrid('getGridParam','selarrrow');
可展开的下级表
<
jQuery("#list11").jqGrid({
q=1',
"xml",
200,
'#pager11',
subGrid:
subGridUrl:
subGridModel:
[{name:
width:
[55,200,80,80,80]}
"SubgridExample"
jQuery("#list11").jqGrid('navGrid','#pager11',{add:
壳展开的下级表2
jQuery("#listsg11").jqGrid({
190,
8,
[8,10,20,30],
'#pagersg11',
"GridasSubgrid",
subGridRowExpanded:
function(subgrid_id,row_id){
//wepasstwoparameters
//subgrid_idisaidofthedivtagcreatedwhitinatabledata
//theidofthiselemenetisacombinationofthe"sg_"+idoftherow
//therow_idistheidoftherow
//Ifwewantopassadditinalparameterstotheurlwecanuse
//amethodgetRowData(row_id)-whichreturnsassociativearrayintypename-value
//herewecaneasyconstructtheflowing
varsubgrid_table_id,pager_id;
subgrid_table_id=subgrid_id+"_t";
pager_id="p_"+subgrid_table_id;
$("#"+subgrid_id).html(
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1