看一下配置文件
代码如下 | 复制代码 |
return array( ), ), ), |
可以通过配置,非常方便修改,并一改全改,增删改。
2,html的jqgrid代码
代码如下 | 复制代码 |
jQuery("#goodsList").jqGrid({ url:'__APP__?m=Home&a=getList', datatype: "json", mtype: 'POST', colNames:['ID',<{$feildname}>,'修改时间','操作'], colModel:[ {name:'id',width:25,index:'id',setGridHeight:"auto"}, <{$feildmap}> {name:'lastdotime',sortable:true}, {name:'edit',search:false,sortable:false}, ], rowNum:10, rowList:[10,20,30], multiselect:true, //复选框 pager: '#goodsPager', sortname: 'lastdotime', viewrecords: true, sortorder: "desc", editurl:'__APP__?m=Home&a=oper',//添加修改操作url autowidth:true, height:'100%' }); |
3,三个比较重要的函数
代码如下 | 复制代码 |
//获取字段名称 function feild_name($feild){ $fields = C($feild); $feild = ''; foreach($fields as $val){ $feild .="'".$val['name']."',"; } $feild = rtrim($feild,','); return $feild; } //获取字段字典 function feild_map($feild){ $fields = C($feild); $feildmap =''; foreach($fields as $key=>$val){ $feildmap .= '{name:\''.$key.'\',sortable:false,editable:true'; if(1==$val['hidden']){ $feildmap .=',hidedlg:true,hidden:true,editrules:{edithidden:true,'; }else{ $feildmap .= ',editrules:{'; } if(1==$val['required']){ $feildmap .='required:true}'; }else{ $feildmap .='required:false}'; } $feildmap .= '},'."\n"; } return $feildmap; } //获取字段列表 function feild_list($feild,$array=array(),$row=array()){ $row = json_decode($row['value'],true); $fields = C($feild); foreach($fields as $key=>$val){ switch($val['type']){ case 'url':$array[]='https://img.111cn.net'.$row[$key].'';break; case 'img':$array[]='';break; default:$array[] = $row[$key]; } } return $array; } |
代码没有什么,就是通过json对象动态配置。