123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Insert title here</title>
- <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqueryui/jquery-ui.css" />
- <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqgrid/css/ui.jqgrid.css" />
- <script type="text/ecmascript" src="${ctx}/assets/lib/jquery/1.9.1/jquery.min.js"></script>
- <script type="text/ecmascript" src="${ctx}/assets/lib/jqueryui/jquery-ui.js"></script>
- <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/i18n/grid.locale-cn.js"></script>
- <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/jquery.jqGrid.min.js"></script>
- <script type="text/javascript" src="${ctx}/assets/lib/layer/3.0.3/layer.js"></script>
- <script type="text/javascript">
- /**
- * 修改JSON中key的方法
- */
- function modifyJosnKey(json,oddkey,newkey){
- var val=json[oddkey];
- delete json[oddkey];
- json[newkey]=val;
- }
- $(function() {
- $("#tree").jqGrid({
- url : '${ctx}/myconsole/datadic/getByTree',
- editurl:"${ctx}/myconsole/datadic/saveOrUpdate2",
- mtype : "POST",
- "hoverrows":false,
- "viewrecords":false,
- "gridview":true,
- "height":"auto",
- //"loadonce":true,
- "rowNum":100,
- "scrollrows":true,
- // enable tree grid
- "treeGrid":true,
- // which column is expandable
- "ExpandColumn":"dicvalue",
- // datatype
- "treedatatype":"json",
- // the model used
- "treeGridModel":"adjacency",
- // configuration of the data comming from server
-
- "sortorder":"asc",
- autowidth : true,
- "datatype":"json",
- "pager":"#pager",
- prmNames : {
- id: "keyid",
- oper:"oper",
- addoper:"add",
- editoper:"edit",
- deloper:"del"
- },
- colModel : [ {
- label : '字典名称',
- name : 'dicvalue',
- edittype : "text",
- editable: true,
- width : 100
- },{
- label : '编号',
- name : 'keyid',
- key : true,
- width : 75
- },{
- label : '树路径',
- name : 'treepath',
- editable : false,
- width : 120
- }, {
- label : '字典键值',
- name : 'dickey',
- edittype : "text",
- editable: true,
- width : 50
- },{
- label : '字典描述',
- name : 'dicdesc',
- editable: true,
- edittype : "textarea",
- editoptions: {
- size:50,
- maxlength: 500,
- rows:"10",
- cols:"40"
- }
- }, {
- label : '排序值',
- name : 'sortid',
- edittype : "text",
- editable: true,
- width : 30
- }, {
- label : '更新时间',
- name : 'updatetime',
- width : 50
- },{
- "name":"parentid",
- "hidden":true
- },{
- "name":"treelevel",
- "hidden":true
- } ],
- "treeReader":{
- "level_field":"treelevel",
- "leaf_field":"isleaf",
- "expanded_field":"expanded",
- "loaded":"loaded",
- "parent_id_field":"parentid",
- "icon_field":"icon"
- }
- });
- jQuery('#tree').jqGrid('navGrid','#pager',
- // the buttons to appear on the toolbar of the grid
- {
- edit : true,
- add : true,
- del : true,
- search : false,
- refresh : true,
- view : false,
- position : "left",
- cloneToTop : true
- },
- // options for the Edit Dialog
- {
- recreateForm : true,
- checkOnUpdate : true,
- checkOnSubmit : true,
- closeAfterEdit : true,
- serializeEditData: function(postdata) {
- //console.log(postdata);
- $.each(postdata,function (index, value) {
- if(index!="jqGrid_id" && index!="oper" && index!="id"){
- modifyJosnKey(postdata,index,"dataDic."+index);
- }
- if(index=="id"){
- postdata["dataDic."+index]=value
- }
- })
- //console.log(postdata);
- return postdata;
- },
- afterSubmit: function (response, postdata) {
- // console.log(response);
- var res=eval('(' + response.responseText + ')');
- //layer.msg(res.msg);
- return [res.state,res.msg,''];
- },
- errorTextFormat : function(data) {
- return 'Error: ' + data.responseText
- }
- },
- // options for the Add Dialog
- {
- closeAfterAdd : true,
- recreateForm : true,
- beforeSubmit: function(postdata, formid){
- var selRowId = $("#tree").jqGrid ('getGridParam', 'selrow');
- //console.log(selRowId);
- postdata.parentid=selRowId;
- if(postdata.parentid==null && postdata.parentid==""){
- postdata.parentid="0";
- }
- $.each(postdata,function (index, value) {
- if(index!="jqGrid_id" && index!="oper"){
- modifyJosnKey(postdata,index,"dataDic."+index);
- }
- })
- return[true,''];
- },
- afterSubmit: function (response, postdata) {
- //console.log(response.responseText);
- var res=eval('(' + response.responseText + ')');
- //layer.msg(res.msg);
- return [res.state,res.msg,''];
- },
- errorTextFormat : function(data) {
- return 'Error: ' + data.responseText
- }
- },
- // options for the Delete Dailog
- {
- errorTextFormat : function(data) {
- return 'Error: ' + data.responseText
- }
- });
- jQuery('#tree').jqGrid('bindKeys');
- })
- </script>
- </head>
- <body>
- <table id="tree"></table>
- <div id="pager"></div>
- </body>
- </html>
|