生成树(treegrid)的数据格式
来源:互联网 发布:六边形战士 知乎 编辑:程序博客网 时间:2024/05/01 04:05
public void ProcessRequest(HttpContext context) { string id = "BUDGET0001";// context.Request.Form["id"];//类型 DataTable ds = new DataTable(); DataTable dt = new DataTable(); string yuyu = ""; string sfile=""; string sfilevalue = ""; string mm = ""; dt = comm_data.gettablebypruce("qg_budget_code","", "qgid asc"); ds = comm_data.gettablebypruce("qg_data", "t.dataid='" + id + "'", "t.displaynum asc"); if (ds.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { yuyu = "{\"id\":\"" + dt.Rows[i]["qgid"].ToString() + "\","; for (int k = 0; k < ds.Rows.Count; k++) { sfile=ds.Rows[k]["datafile"].ToString(); sfilevalue = dt.Rows[i][sfile].ToString(); if (sfile == "BUDGETPARENTCODE") { if (sfilevalue!="") { yuyu = yuyu + "\"_parentId\":\"" + sfilevalue + "\","; } } yuyu = yuyu + "\"" + sfile + "\":\"" + sfilevalue + "\","; } yuyu = yuyu.Substring(0, yuyu.Length - 1); mm = mm + "," + yuyu + "}"; } mm = mm.Remove(0, 1); mm = "{\"total\":\"88888\",\"rows\":[" + mm + "]}"; } context.Response.Write(mm); }
格式为:{“total":88,"rows":[ {"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},{ },{ }]}
不面是结合数据库表data中已经设置好的数据字段及进行
<table id="dg"></table> <script> function formatPrice(val, row) { var str=""; var cc=row.BUDGETCODE.length; if ( cc> 1) { for (var i = 1; i <cc; i++) { str = str + " " } return str+ val; } else { return val; } } function formartid(a) { var str; if (a.length>1) { for(var i=1;i<a.length;i++) str=str+" " } return str+a; } $('#dg').edatagrid({ url: '../ashprama/test01.ashx', title: '11111', fit: false, columns: [[ { field: 'QGID', title: 'ID', width: '30', hidden: 'true' }, { field: 'BUDGETNAME', title: '类别', width: '200', formatter: formatPrice }, { field: 'BUDGETCODE', title: '代码', width: '50' }, { field: 'BUDGETPARENTCODE', title: '父类代码', width: '75', hidden: 'true' }, { field: 'CONTRACTID', title: '合同编号', width: '204', editor: 'text' }, { field: 'CONTRACTNAME', title: '合同名称', width: '120', editor: 'text' }, { field: 'REMARK', title: '备注', width: '120', editor: 'text' }, { field: 'COSTS', title: '成本 ', width: '120', editor: 'text' }, { field: 'QMONEY', title: '资金', width: '70', editor: 'text' } ]]}) </script>
(function ($) { // var oldLoadDataMethod = $.fn.datagrid.methods.loadData; // $.fn.datagrid.methods.loadData = function(jq, data){ // jq.each(function(){ // $.data(this, 'datagrid').filterSource = null; // }); // return oldLoadDataMethod.call($.fn.datagrid.methods, jq, data); // }; var currTarget; $(function () { $(document).unbind('.edatagrid').bind('mousedown.edatagrid', function (e) { var p = $(e.target).closest('div.datagrid-view,div.combo-panel'); if (p.length) { if (p.hasClass('datagrid-view')) { var dg = p.children('table'); if (dg.length && currTarget != dg[0]) { _save(); } } return; } _save(); function _save() { var dg = $(currTarget); if (dg.length) { dg.edatagrid('saveRow'); currTarget = undefined; } } }); }); function buildGrid(target) { var opts = $.data(target, 'edatagrid').options; $(target).datagrid($.extend({}, opts, { onDblClickCell: function (index, field, value) { if (opts.editing) { $(this).edatagrid('editRow', index); focusEditor(field); } if (opts.onDblClickCell) { opts.onDblClickCell.call(target, index, field, value); } }, onClickCell: function (index, field, value) { if (opts.editing && opts.editIndex >= 0) { $(this).edatagrid('editRow', index); focusEditor(field); } if (opts.onClickCell) { opts.onClickCell.call(target, index, field, value); } }, onAfterEdit: function (index, row) { opts.editIndex = -1; var url = row.isNewRecord ? opts.saveUrl : opts.updateUrl; // if if (url) { $.post(url, row, function (data) { if (data.isError) { $(target).edatagrid('cancelRow', index); $(target).edatagrid('selectRow', index); $(target).edatagrid('editRow', index); opts.onError.call(target, index, data); return; } data.isNewRecord = null; $(target).datagrid('updateRow', { index: index, row: data }); if (opts.tree) { var idValue = row[opts.idField || 'id']; var t = $(opts.tree); var node = t.tree('find', idValue); if (node) { node.text = row[opts.treeTextField]; t.tree('update', node); } else { var pnode = t.tree('find', row[opts.treeParentField]); t.tree('append', { parent: (pnode ? pnode.target : null), data: [{ id: idValue, text: row[opts.treeTextField] }] }); } } opts.onSave.call(target, index, row); }, 'json'); } else { opts.onSave.call(target, index, row); } if (opts.onAfterEdit) opts.onAfterEdit.call(target, index, row); }, onCancelEdit: function (index, row) { opts.editIndex = -1; if (row.isNewRecord) { $(this).datagrid('deleteRow', index); } if (opts.onCancelEdit) opts.onCancelEdit.call(target, index, row); }, onBeforeLoad: function (param) { if (opts.onBeforeLoad.call(target, param) == false) { return false } $(this).edatagrid('cancelRow'); if (opts.tree) { var node = $(opts.tree).tree('getSelected'); param[opts.treeParentField] = node ? node.id : undefined; } } })); function focusEditor(field) { var editor = $(target).datagrid('getEditor', { index: opts.editIndex, field: field }); if (editor) { editor.target.focus(); } else { var editors = $(target).datagrid('getEditors', opts.editIndex); if (editors.length) { editors[0].target.focus(); } } } if (opts.tree) { $(opts.tree).tree({ url: opts.treeUrl, onClick: function (node) { $(target).datagrid('load'); }, onDrop: function (dest, source, point) { var targetId = $(this).tree('getNode', dest).id; $.ajax({ url: opts.treeDndUrl, type: 'post', data: { id: source.id, targetId: targetId, point: point }, dataType: 'json', success: function () { $(target).datagrid('load'); } }); } }); } } $.fn.edatagrid = function (options, param) { if (typeof options == 'string') { var method = $.fn.edatagrid.methods[options]; if (method) { return method(this, param); } else { return this.datagrid(options, param); } } options = options || {}; return this.each(function () { var state = $.data(this, 'edatagrid'); if (state) { $.extend(state.options, options); } else { $.data(this, 'edatagrid', { options: $.extend({}, $.fn.edatagrid.defaults, $.fn.edatagrid.parseOptions(this), options) }); } buildGrid(this); }); }; $.fn.edatagrid.parseOptions = function (target) { return $.extend({}, $.fn.datagrid.parseOptions(target), { }); }; $.fn.edatagrid.methods = { options: function (jq) { var opts = $.data(jq[0], 'edatagrid').options; return opts; }, loadData: function (jq, data) { return jq.each(function () { $(this).edatagrid('cancelRow'); $(this).datagrid('loadData', data); }); }, enableEditing: function (jq) { return jq.each(function () { var opts = $.data(this, 'edatagrid').options; opts.editing = true; }); }, disableEditing: function (jq) { return jq.each(function () { var opts = $.data(this, 'edatagrid').options; opts.editing = false; }); }, editRow: function (jq, index) { return jq.each(function () { var dg = $(this); var opts = $.data(this, 'edatagrid').options; var editIndex = opts.editIndex; if (editIndex != index) { if (dg.datagrid('validateRow', editIndex)) { if (editIndex >= 0) { if (opts.onBeforeSave.call(this, editIndex) == false) { setTimeout(function () { dg.datagrid('selectRow', editIndex); }, 0); return; } } dg.datagrid('endEdit', editIndex); dg.datagrid('beginEdit', index); opts.editIndex = index; if (currTarget != this && $(currTarget).length) { $(currTarget).edatagrid('saveRow'); currTarget = undefined; } if (opts.autoSave) { currTarget = this; } var rows = dg.datagrid('getRows'); opts.onEdit.call(this, index, rows[index]); } else { setTimeout(function () { dg.datagrid('selectRow', editIndex); }, 0); } } }); }, addRow: function (jq, index) { return jq.each(function () { var dg = $(this); var opts = $.data(this, 'edatagrid').options; if (opts.editIndex >= 0) { if (!dg.datagrid('validateRow', opts.editIndex)) { dg.datagrid('selectRow', opts.editIndex); return; } if (opts.onBeforeSave.call(this, opts.editIndex) == false) { setTimeout(function () { dg.datagrid('selectRow', opts.editIndex); }, 0); return; } dg.datagrid('endEdit', opts.editIndex); } var rows = dg.datagrid('getRows'); function _add(index, row) { index = dg.datagrid('getRowIndex', dg.datagrid('getSelected')) // alert(index); if (index == -1) { dg.datagrid('appendRow', row); opts.editIndex = rows.length - 1; } else { dg.datagrid('insertRow', { index: index, row: row }); opts.editIndex = index; } } if (typeof index == 'object') { _add(index.index, $.extend(index.row, { isNewRecord: true })) } else { _add(index, { isNewRecord: true }); } //if (index == undefined){ //dg.datagrid('appendRow', {isNewRecord:true}); //opts.editIndex = rows.length - 1; //} else { //dg.datagrid('insertRow', { //index: index, //row: {isNewRecord:true} //}); //opts.editIndex = index; //} dg.datagrid('beginEdit', opts.editIndex); dg.datagrid('selectRow', opts.editIndex); if (opts.tree) { var node = $(opts.tree).tree('getSelected'); rows[opts.editIndex][opts.treeParentField] = (node ? node.id : 0); } opts.onAdd.call(this, opts.editIndex, rows[opts.editIndex]); }); }, saveRow: function (jq) {//返回的是一个数据集,即新增加的数据集 return jq.each(function () { var dg = $(this); var opts = $.data(this, 'edatagrid').options; if (opts.editIndex >= 0) { if (opts.onBeforeSave.call(this, opts.editIndex) == false) { setTimeout(function () { dg.datagrid('selectRow', opts.editIndex); }, 0); return; } $(this).datagrid('endEdit', opts.editIndex); } // alert("1"); }); }, cancelRow: function (jq) { return jq.each(function () { var opts = $.data(this, 'edatagrid').options; if (opts.editIndex >= 0) { $(this).datagrid('cancelEdit', opts.editIndex); } }); }, destroyRow: function (jq, index) { return jq.each(function () { var dg = $(this); var opts = $.data(this, 'edatagrid').options; var rows = []; if (index == undefined) { rows = dg.datagrid('getSelections'); } else { var rowIndexes = $.isArray(index) ? index : [index]; for (var i = 0; i < rowIndexes.length; i++) { var row = opts.finder.getRow(this, rowIndexes[i]); if (row) { rows.push(row); } } } if (!rows.length) { $.messager.show({ title: opts.destroyMsg.norecord.title, msg: opts.destroyMsg.norecord.msg }); return; } $.messager.confirm(opts.destroyMsg.confirm.title, opts.destroyMsg.confirm.msg, function (r) { if (r) { for (var i = 0; i < rows.length; i++) { _del(rows[i]); } dg.datagrid('clearSelections'); } }); function _del(row) { var index = dg.datagrid('getRowIndex', row); if (index == -1) { return } if (row.isNewRecord) { dg.datagrid('cancelEdit', index); } else { if (opts.destroyUrl) { var idValue = row[opts.idField || 'id']; $.post(opts.destroyUrl, { id: idValue }, function (data) { var index = dg.datagrid('getRowIndex', idValue); if (data.isError) { dg.datagrid('selectRow', index); opts.onError.call(dg[0], index, data); return; } if (opts.tree) { dg.datagrid('reload'); var t = $(opts.tree); var node = t.tree('find', idValue); if (node) { t.tree('remove', node.target); } } else { dg.datagrid('cancelEdit', index); dg.datagrid('deleteRow', index); } opts.onDestroy.call(dg[0], index, row); var pager = dg.datagrid('getPager'); if (pager.length && !dg.datagrid('getRows').length) { dg.datagrid('options').pageNumber = pager.pagination('options').pageNumber; dg.datagrid('reload'); } }, 'json'); } else { dg.datagrid('cancelEdit', index); dg.datagrid('deleteRow', index); opts.onDestroy.call(dg[0], index, row); } } } }); } }; $.fn.edatagrid.defaults = $.extend({}, $.fn.datagrid.defaults, { singleSelect: true, editing: true, editIndex: -1, destroyMsg: { norecord: { title: 'Warning', msg: 'No record is selected.' }, confirm: { title: 'Confirm', msg: 'Are you sure you want to delete?' } }, //destroyConfirmTitle: 'Confirm', //destroyConfirmMsg: 'Are you sure you want to delete?', autoSave: false,// auto save the editing row when click out of datagrid url: null,// return the datagrid data saveUrl: null,// return the added row updateUrl: null,// return the updated row destroyUrl: null,// return {success:true} tree: null,// the tree selector treeUrl: null,// return tree data treeDndUrl: null,// to process the drag and drop operation, return {success:true} treeTextField: 'name', treeParentField: 'parentId', onAdd: function (index, row) { }, onEdit: function (index, row) { }, onBeforeSave: function (index) { }, onSave: function (index, row) {}, onDestroy: function (index, row) { }, onError: function (index, row) { } }); //////////////////////////////// $.parser.plugins.push('edatagrid');})(jQuery);function submitnewdata() { var data = $('#dg').edatagrid('saveRow'); var rows = data.edatagrid('getChanges'); // alert(rows); if (rows.length > 0) { for (var i = 0; i < rows.length; i++) { alert(rows[i].QGID); } } // $.post("aspsd.aspx", rows, function (data) { })}
0 0
- 生成树(treegrid)的数据格式
- easyui中treegrid的数据格式
- easyui-treegrid 加载数据格式
- easyui加载datagrid和treegrid的几种json数据格式
- easyui加载datagrid和treegrid的几种json数据格式
- EasyUI treegrid 生成json格式的方法
- 关于easyui treegrid 的数据格式的修改 完成类似于id pid 的平行数据
- JEECG树(TreeGrid)字段的扩展
- C#生成JSON数据格式的函数
- 生成libSVM的数据格式及使用方法总结
- 生成libSVM的数据格式及使用方法
- 生成libSVM的数据格式及使用方法总结
- 使用python生成libSVM的数据格式
- 生成libSVM的数据格式及使用方法总结
- 2014/3/14 easyUI中treeGrid json数据格式
- treeGrid的使用方法
- TreeGrid的属性介绍
- ExtJS TreeGrid的用法
- 联想G510进入BIOS的两种方法
- Linux 进程间通信
- Lifetime Improvement of NAND Flash-based Storage Systems Using Dynamic Program and Erase Scaling
- 【高级算法】Lasvegas算法解决3SAT问题(C++实现代码)
- 无限级分类展示
- 生成树(treegrid)的数据格式
- sgu265:Wizards(计算几何)
- 日志框架实现实时修改,实时生效,具体框架思路(1)
- 二维DCT变换
- Android网络编程之传递数据给服务器
- 细说linux性能优化
- JVM的gc概述
- c++ & * 符号的多重含义
- quick3x_游戏场景计时器