easyui tree操作

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2 <html>
  3 <head>
  4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5     <meta name="keywords" content="jquery,ui,easy,easyui,web">
  6     <meta name="description" content="easyui help you build your web page easily!">
  7     <title>DataGrid inline editing - jQuery EasyUI Demo</title>
  8     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/default/easyui.css">
  9     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/icon.css">
 10     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/demo/demo.css">
 11     <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
 12     <script type="text/javascript" src="http://www.jeasyui.net/Public/js/easyui/jquery.easyui.min.js"></script>
 13     <script>
 14         var data = {"total":28,"rows":[
 15             {"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":16.50,"attr1":"Large","itemid":"EST-1"},
 16             {"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
 17             {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"},
 18             {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Rattleless","itemid":"EST-12"},
 19             {"productid":"RP-LI-02","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Green Adult","itemid":"EST-13"},
 20             {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":58.50,"attr1":"Tailless","itemid":"EST-14"},
 21             {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"With tail","itemid":"EST-15"},
 22             {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Female","itemid":"EST-16"},
 23             {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Male","itemid":"EST-17"},
 24             {"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":193.50,"attr1":"Adult Male","itemid":"EST-18"}
 25         ]};
 26
 27         var products = [
 28             {productid:‘FI-SW-01‘,name:‘Koi‘},
 29             {productid:‘K9-DL-01‘,name:‘Dalmation‘},
 30             {productid:‘RP-SN-01‘,name:‘Rattlesnake‘},
 31             {productid:‘RP-LI-02‘,name:‘Iguana‘},
 32             {productid:‘FL-DSH-01‘,name:‘Manx‘},
 33             {productid:‘FL-DLH-02‘,name:‘Persian‘},
 34             {productid:‘AV-CB-01‘,name:‘Amazon Parrot‘}
 35         ];
 36         $(function(){
 37             $(‘#tt‘).datagrid({
 38                 title:‘Editable DataGrid‘,
 39                 iconCls:‘icon-edit‘,
 40                 width:660,
 41                 height:250,
 42                 singleSelect:true,
 43                 idField:‘itemid‘,
 44                 data:data,
 45                 columns:[[
 46                     {field:‘itemid‘,title:‘Item ID‘,width:60},
 47                     {field:‘productid‘,title:‘Product‘,width:100,
 48                         formatter:function(value){
 49                             for(var i=0; i<products.length; i++){
 50                                 if (products[i].productid == value) return products[i].name;
 51                             }
 52                             return value;
 53                         },
 54                         editor:{
 55                             type:‘combobox‘,
 56                             options:{
 57                                 valueField:‘productid‘,
 58                                 textField:‘name‘,
 59                                 data:products,
 60                                 required:true
 61                             }
 62                         }
 63                     },
 64                     {field:‘listprice‘,title:‘List Price‘,width:80,align:‘right‘,editor:{type:‘numberbox‘,options:{precision:1}}},
 65                     {field:‘unitcost‘,title:‘Unit Cost‘,width:80,align:‘right‘,editor:‘numberbox‘},
 66                     {field:‘attr1‘,title:‘Attribute‘,width:180,editor:‘text‘},
 67                     {field:‘status‘,title:‘Status‘,width:50,align:‘center‘,
 68                         editor:{
 69                             type:‘checkbox‘,
 70                             options:{
 71                                 on: ‘P‘,
 72                                 off: ‘‘
 73                             }
 74                         }
 75                     },
 76                     {field:‘action‘,title:‘Action‘,width:80,align:‘center‘,
 77                         formatter:function(value,row,index){
 78                             if (row.editing){
 79                                 var s = ‘<a href="#" onclick="saverow(this)">Save</a> ‘;
 80                                 var c = ‘<a href="#" onclick="cancelrow(this)">Cancel</a>‘;
 81                                 return s+c;
 82                             } else {
 83                                 var e = ‘<a href="#" onclick="editrow(this)">Edit</a> ‘;
 84                                 var d = ‘<a href="#" onclick="deleterow(this)">Delete</a>‘;
 85                                 return e+d;
 86                             }
 87                         }
 88                     }
 89                 ]],
 90                 onBeforeEdit:function(index,row){
 91                     row.editing = true;
 92                     updateActions(index);
 93                 },
 94                 onAfterEdit:function(index,row){
 95                     row.editing = false;
 96                     updateActions(index);
 97                 },
 98                 onCancelEdit:function(index,row){
 99                     row.editing = false;
100                     updateActions(index);
101                 }
102             });
103         });
104         function updateActions(index){
105             $(‘#tt‘).datagrid(‘updateRow‘,{
106                 index: index,
107                 row:{}
108             });
109         }
110         function getRowIndex(target){
111             var tr = $(target).closest(‘tr.datagrid-row‘);
112             return parseInt(tr.attr(‘datagrid-row-index‘));
113         }
114         function editrow(target){
115             $(‘#tt‘).datagrid(‘beginEdit‘, getRowIndex(target));
116         }
117         function deleterow(target){
118             $.messager.confirm(‘Confirm‘,‘Are you sure?‘,function(r){
119                 if (r){
120                     $(‘#tt‘).datagrid(‘deleteRow‘, getRowIndex(target));
121                 }
122             });
123         }
124         function saverow(target){
125             $(‘#tt‘).datagrid(‘endEdit‘, getRowIndex(target));
126         }
127         function cancelrow(target){
128             $(‘#tt‘).datagrid(‘cancelEdit‘, getRowIndex(target));
129         }
130         function insert(){
131             var row = $(‘#tt‘).datagrid(‘getSelected‘);
132             if (row){
133                 var index = $(‘#tt‘).datagrid(‘getRowIndex‘, row);
134             } else {
135                 index = 0;
136             }
137             $(‘#tt‘).datagrid(‘insertRow‘, {
138                 index: index,
139                 row:{
140                     status:‘P‘
141                 }
142             });
143             $(‘#tt‘).datagrid(‘selectRow‘,index);
144             $(‘#tt‘).datagrid(‘beginEdit‘,index);
145         }
146     </script>
147 </head>
148 <body>
149     <h2>Editable DataGrid Demo</h2>
150     <div class="demo-info">
151         <div class="demo-tip icon-tip">&nbsp;</div>
152         <div>Click the edit button on the right side of row to start editing.</div>
153     </div>
154
155     <div style="margin:10px 0">
156         <a href="#" class="easyui-linkbutton" onclick="insert()">Insert Row</a>
157     </div>
158
159     <table id="tt"></table>
160
161 </body>
162 </html>
 1 {"total":28,"rows":[
 2     {"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":16.50,"attr1":"Large","itemid":"EST-1"},
 3     {"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
 4     {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"},
 5     {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Rattleless","itemid":"EST-12"},
 6     {"productid":"RP-LI-02","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Green Adult","itemid":"EST-13"},
 7     {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":58.50,"attr1":"Tailless","itemid":"EST-14"},
 8     {"productid":"FL-DSH-01","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"With tail","itemid":"EST-15"},
 9     {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Female","itemid":"EST-16"},
10     {"productid":"FL-DLH-02","unitcost":12.00,"status":"P","listprice":93.50,"attr1":"Adult Male","itemid":"EST-17"},
11     {"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":193.50,"attr1":"Adult Male","itemid":"EST-18"}
12 ]}
时间: 2024-11-03 03:32:40

easyui tree操作的相关文章

Jquery easyui tree的使用

这个ui用的一切都是json数据.树也是如此! 后台需要返回与格式匹配的json数据才能正确加载树. 页面定义一个ui: <ul id="messageInfoAddTree" class="easyui-tree" checkbox="true" data-options="lines:true" style="height:94%"></ul> JS访问后台: //人员树 $('

Jquery EasyUI Tree树形结构的Java实现(实体转换VO)

前一阵做的OA项目,有一个是组织架构的树,因为是分开做的,我做的是Controller和页面,其他组做的Service和Dao,因为之前一直没有商量页面用什么框架做比较好,导致,Dao层取出来的数据都不是Easyui Tree所能识别的,其实后台返回的也是树形的结构,但是他们返回来的 **id,而不是Easyui Tree所能识别的id:他们返回的是name,,而不是Easyui Tree所能识别的text,他们返回的是****,,而不是Easyui Tree所能识别的children,因为别人

EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中

需求:EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中 效果: /**   * 给树增加onCheck事件,首先使用cascadeCheck:false属性禁止全选,   * 然后获取当前选中节点的所有子节点,在判断其拥有子节点时对其所有字节点   * 进行遍历操作.在easyui中树节点的是否选中不是由checked:true   * 属性来控制,而是由class tree-checkbox0   * 和tree-checkbox1进行控制.--by wk   */  

递归和循环---从EasyUI Tree 发现自己的硬伤

前一阵子,朋友托我帮忙用vb.net写一个数独游戏,我当时的第一个想法---万能的互联网肯定有资源,肯定有人写---当然这是必须的---我站在巨人的肩膀上帮朋友完成代码---但是我突然觉得自己站在巨人这么高的肩膀上太高耸,想要找一下脚踏实地的感觉,所以我想自己写写,看看能不能写出来,结果就是------我压根没有思路. 对,毫不夸张,无从下手. 更深刻的一件事就是项目中用的的树状结构(easyui tree 实现),同样是根据数据库动态生成,我站在巨人的肩膀上,看着网上类似的datatable转

JQuery EasyUi Tree获取所有checkbox选中节点的id和内容

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>    <head>        <meta name="generator" content="HTML Tidy, see www.w3.org">      

[转]easyui tree 模仿ztree 使用扁平化加载json

原文地址:http://my.oschina.net/acitiviti/blog/349377 参考文章:http://www.jeasyuicn.com/demo/treeloadfilter.html 一.扩展原因 ztree使用了一种扁平化的数据加载方式,就是id(自身id),pid(父id)的方式,参考http://www.ztree.me/v3/demo.php#_102,于是扩展easyui tree 也使用这种亲民的方式: 二.基本方法 1,载入扩展文件 2,在JS中实例化TRE

Easyui Tree方法扩展 - getLevel(获取节点级别)

Easyui Tree一直就没有提供这个方法,以前没有用到,所以一直没怎么在意,这次自己用到了,顺便扩展了一个方法,分享给大家. $.extend($.fn.tree.methods, { getLevel:function(jq,target){ var l = $(target).parentsUntil("ul.tree","ul"); return l.length+1; } }); 用法: var node = $().tree("getSele

EasyUI tree读取sql server的表结构得到json格式

本来项目需要一个tree的树结构,后来随便选择了一个easyUI tree开源框架,后来碰到一个问题,我是要从数据库递归出结构的,转成json的,怎么做?难道是递归了拼接StringBuilder?要是这样做就太傻了,当时也打算这么做.然后各种百度,博客园,QQ群去问,回答的也是五花八门,没人给我指点详细的,我只好自己琢磨了. 第一:递归数据库的表. 第二:序列化最后的递归结果. 这里是我的数据库的表: 然后下面是代码: 这里需要建立一个实体类,类的属性跟数据库表的一样,只是多了一个泛型属性,是

easyui tree末端子菜单显示:

easyui树形显示注意事项: [{"id":"01","text":"商户管理","state":"closed","checked":true,"children":[{"id":"0100","text":"商户管理","state":&quo