09-02-13 更新:
感谢 tufei2006同学分享的一个demo演示 猛击这里
12.3 更新:
有群众反映jqgrid的库下不回来,我在这里贴一下吧.还有我没写过这个jsp例子.不过基本上大同小异.都是用json数据交换的.
list.html
会员管理
manage_user.js
var lastsel2=0; $(function(){ $('#grid').jqGrid({ height:400, url:'?module=user&act=list&isajax=1', datatype: 'json', mtype: 'POST', colNames:['ID','用户名','密码','真实姓名','联系电话', 'Email'], colModel :[ { name:'id', index:'id', width:50 }, { name:'UserName', index:'UserName', editable:true, editrules:{ required:true } }, { name:'PassWord', index:'PassWord', editable:true, edittype:'password', hidden:true, editoptions:{ size:20 }, editrules:{ edithidden:true } }, { name:'LinkMan', index:'LinkMan', editable:true, editrules:{ required:true } }, { name:'OperateTel', index:'OperateTel', align:'right', editable:true, editrules:{ required:true } }, { name:'Email', index:'Email', align:'right', editable:true, editrules:{ required:true } } ], pager: 'nav', rowNum:10, rowList:[10,20,30], sortname: 'MemberID', sortorder: "desc", viewrecords: true, imgpath: '../resources/js/jqGrid/themes/basic/images', caption: '用户管理', // multikey:'ctrlKey', multiselect:true, editurl:'?module=user&act=Update' }); //定义按键 $('#grid').navGrid('#nav',{ refresh: true, edit: true, add: true, del: true, search: true }); });
user.php
function onList(){ $in = &$this->in; $tpl = &$this->tpl; $dataset = &$this->objDataSet; $isAjax = $in['isajax']; if($isAjax){ $page = $_POST['page']; $rp = $_POST['rows']; $sortname = $_POST['sidx']; $sortorder = $_POST['sord']; $q=$in['searchField']; $opr=$in['searchOper']; $q_val=$in['searchString']; if (!$sortname) $sortname = 'MemberID'; if (!$sortorder) $sortorder = 'desc'; $sort = "ORDER BY $sortname $sortorder"; if (!$page) $page = 1; if (!$rp) $rp = 10; $start = (($page-1) * $rp); $limit = "LIMIT $start, $rp "; $sql="select MemberID,UserName,'' as PassWord,LinkMan,OperateTel,Email from user $sort"; $total=$dataset->runSql("select count(*) as total from user"); $total=(int)$total['total']; $result=$dataset->getLista($sql,$rp,$start); // $this->fp->fb($result); $ret="{'page':'$page','total':'".ceil($total/$rp)."','records':'$total','rows':["; if (!empty($result)) { foreach($result as $key=>$row){ if($key>0)$ret.=","; $ret.="{'id':'".$row[MemberID]."',"; $ret.="'cell':["; $i=0; foreach($row as $k=>$val){ if($i)$ret.=","; $ret.="'".$val."'"; $i++; } $ret.="]}"; }} $ret.="]}"; $tpl->assign('ret',$ret); $tpl->display('./rep.json'); }else{ // $tpl->assign('entities',$result); $tpl->display(SKIN_FILE.'user/list.html'); } } function onUpdate(){ $in=&$this->in; if ($in['oper']=='del') { $this->onDelete((int)$in['id']); }else{ $this->onInsertOrUpdate($in['oper']); } } //会员添加 function onInsertOrUpdate($_act='add'){ $in = &$this->in; $tpl = &$this->tpl; $dataset = &$this->objDataSet; $data = array( Email => trim($in[Email]), OperateTel => trim($in[OperateTel]), LinkMan => trim($in[LinkMan]) ); if (!empty($in['PassWord'])) { $data['PassWord']=md5(trim($in['PassWord'])); } if($_act=='edit'){ $MemberID = $dataset->update($data,"MemberID=".(int)$in['id'],"user"); }else{ $data['UserName']=$in['UserName']; $data['CreateTime']=time(); $MemberID = $dataset->insert($data,"user"); } $ret=json_encode(array('succees'=>true,'msg'=>'更新成功!')); $tpl->assign('ret',$ret); $tpl->display('./rep.json'); } function onDelete($_id=0){ $in = &$this->in; $tpl = &$this->tpl; $dataset = &$this->objDataSet; if ($_id==0) { $_id=(int)$in['MemberID']; } $dataset->delete("MemberID in(0,".$_id.")",'user'); $ret=json_encode(array('succees'=>true,'msg'=>'删除成功!')); $tpl->assign('ret',$ret); $tpl->display('./rep.json'); }