Jquery easy ui datagrid動態加載列問題_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Jquery easy ui datagrid動態加載列問題

Jquery easy ui datagrid動態加載列問題

 2015/3/30 21:31:40  绿茶/  程序员俱乐部  我要评论(0)
  • 摘要:1.如下图效果是当选择不同的日期范围时datagrid则会加载出对应的列数2.首先是后台组装数据,我采用的是循环并拼接DataTable数据,如下代码//循環添加datagrid所需的表頭數據for(inti=0;i<table.Columns.Count;i++){columns.AppendFormat("{{field:'{0}',title:'{1}',align:'center',width:{2}}},",table.Columns[i].ColumnName,table
  • 标签:tag jQuery

1.如下图效果是当选择不同的日期范围时datagrid则会加载出对应的列数

QQQgghhBASKrSjhBBCCCGEEEIihHaUEEIIIYQQQkiEiNvRO0MIIYQQQgghhIQK7SghhBBCCCGEkAhp346+epc9/p/14/9dP/l9L789yK+/rR79z/rRf69fvs6ibyohhBBCCCGEkHTSvh19+S5/9lf+5nOxuihWF2p1oU4v1Om5Or1Qqwu1uihWF8XpefHyQ/74n9nB2zz6phJCCCGEEEIISSft29EXR8XBB7UujNbGGKO/G/3dKG20vn9sjNFaL7+qX//Mn797sIT/+NvT//jb09ICayeWZrDOL3xqN0P1QfC029hhaiOEEEIIIYSQWOkwOvq+OPig1jdaa22M0dpobdSdUep+Bq2NUnp5oX79qzh4V15CtcXydGieyOfcb+2sX1oXK1yysAGW1299YfTThRBCCCGEEEJCpdvo6Pu9dvT7z3a0UKbYNqW3+virevJaHRyp2lLko6PVDk3eLgpn8BRgnbm2HW0xUbJwQgghhBBCCBlpurej9z+sa74/6Ei3Y6TFrV5+VU9eF/vtqGvQzzOx9Ng/jGmd2bP26mKtC7ROkTSK8s5TOI5KCCGEEEIIIRNI9x/Wvf9volvbjvS+Kb0z6lYvv+onb7uOjnpGOF2zCXvO2rHQFjXLt8u/XrpQQgghhBBCyITToR09+tGOar393UW7XlTfbQdIdV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UBABoIXw7OszQaGqjo66fEW0xOlr6strWCl84Up5tse4K634Y9R5AClzfX5xaRvY96Jm/V7whAAAwLsHa0V1LNkwvmsjoqKsR9Qx++kdHq489V1TWtXt64z708XdH9ze5uqN2TalnzwcsySR5f52SJFqXVD3xQn1bTWAvCd+4rHP2VFJ1jda3kXbL7FhSfyhJIsGSAAAlvfyw7nxGR/2XONa2qjqPv/N0PQYAAACAURtrO8otz0TM4UAkuI2UJEFJEpQkQUkSlAQAaGGs7ejwo6MAAAAAgIDG2o5yyzMRczgQCW4jJUlQkgQlSVCSBCUBAFoYazvK6CgAAAAAjNpY21FueSZiDgciwW2kJAlKkqAkCUqSoCQAQAtjbUcZHQUAAACAUZO2oyox3PJMxBwORILbSEkSlCRBSRKUJEFJAIAWxtqOKqUG20cAAAAAgOCk7aj5cZcxkX+jF8C/uwMRvYYZnmzRC6AkSqIkShpLSQCAlDVoR1OTAwAAAABGS9qOEkIIIYQQQgghASNqRwEAAAAACEvUjv4nAAAAAABB/T9GpUcM0yEGXwAAAABJRU5ErkJggg==" alt="" />

 

 

2.首先是后台组装数据,我采用的是循环并拼接DataTable数据,如下代码

          //循環添加datagrid所需的表頭數據
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    columns.AppendFormat("{{field:'{0}',title:'{1}',align:'center',width:{2}}},", table.Columns[i].ColumnName, table.Columns[i].ColumnName, 41);
                }
                //刪除最有一個filed多餘的","號
                if (table.Columns.Count > 0)
                {
                    columns.Remove(columns.Length - 1, 1);
                }
                columns.Append("]]");
                //組裝工令各站排程達成狀況表頭和數據 
                Dictionary<string, object> objDic = new Dictionary<string, object>();
                objDic.Add("columns", columns.ToString()); //datagrid表头
                objDic.Add("rows", table); //datagrid表数据
          //转换为Json格式
return Common.JsonHelper.ToJson(objDic)

 

3.取得浏览器所返回的组装后的JSON格式数据,如下

{"columns":"[[{field:'Item',title:'項目',align:'center',width:120},{field:'SumMonth',title:'3月份累計',align:'center',width:70},{field:'03/01',title:'03/01',align:'center',width:41},{field:'03/02',title:'03/02',align:'center',width
:41},{field:'03/03',title:'03/03',align:'center',width:41},{field:'03/04',title:'03/04',align:'center',width:41},{field:'03/05',title:'03/05',align:'center',width:41},{field:'03/06',title:'03/06',align:'center',width:41},
{field:'03/07',title:'03/07',align:'center',width:41},{field:'03/08',title:'03/08',align:'center',width:41},{field:'03/09',title:'03/09',align:'center',width:41},{field:'03/10',title:'03/10',align:'center',width:41},
{field:'03/11',title:'03/11',align:'center',width:41},{field:'03/12',title:'03/12',align:'center',width:41},{field:'03/13',title:'03/13',align:'center',width:41}]]
",

"rows":[{"SerailNum":1,"Item":"累計各LOT耗用工時之合(H)","SumMonth":142.00,"03/01":null,"03/02":null,"03/03":null,"03/04":50.00,"03/05":null,"03/06":7.00,"03/07":42.00,"03/08":null,"03/09":null,"03/10":17.00,"03/11":null,"03/12":26.00,"03/13":null},{"SerailNum":2,"Item":"產出LOT批","SumMonth":13.00,"03/01":0.00,"03/02":0.00,"03/03":0.00,"03/04":2.00,"03/05":0.00,"03/06":4.00,"03/07":2.00,"03/08":0.00,"03/09":0.00,"03/10":1.00,"03/11":0.00,"03/12":4.00,"03/13":0.00},{"SerailNum":3,"Item":"平均實際CT","SumMonth":10.92,"03/01":null,"03/02":null,"03/03":null,"03/04":25.00,"03/05":null,"03/06":1.75,"03/07":21.00,"03/08":null,"03/09":null,"03/10":17.00,"03/11":null,"03/12":6.50,"03/13":null}]}

 

4.浏览器端解析数据,并绑定datagrid

            //綁定工令各站排程達成狀況
                    $("#dg_PDL_RealCT").datagrid({
                        width: 'auto',  //寬度
                        height: 'auto',  //高度
                        singleSelect: true, //允許選中一行
                        striped: true, //设置为true将交替显示行背景。
                        rownumbers: true, //顯示行號
                        title: "站別實際CT-日報", //標題
                        iconCls: "icon-save", //圖表
                        collapsible: true, //隱藏按鈕
                        method: "post", //post請求
                        showFooter: true,
                        loadMsg: "數據加載中...", //載入信息時提示內容
                        onLoadError: function () {
                            $.messager.alert('溫馨提示', "加载数据失败!!!");
                        },
                        view: myview,
                        emptyMsg: '沒有檢索到相關數據!'
                    }); //end datagrid

                    //綁定工令各站排程達成狀況表頭
                    $.post("/PI/PDL_RealCT", { "BDate": $("#BDate").datebox('getValue'), "EDate": $("#EDate").datebox('getValue'), "ProcCode": $("#ProcCode").combobox('getValue') }, function (data) {
                        setTimeout(function () {
                //将json格式数据转换为js对象
var json = eval("(" + data + ")");
                //获取datagrid熟悉对象 并为其赋值
var opt = $("#dg_PDL_RealCT").datagrid('options');
                //为datagrid表头赋值 opt.columns
= eval(json.columns); $("#dg_PDL_RealCT").datagrid(opt);
                //加载datagrid内容 $(
"#dg_PDL_RealCT").datagrid("loadData", json.rows); $.messager.progress('close'); }, 1000); //end setTimeout }); //end postgh

 

上一篇: StringBuffer的常用方法 下一篇: 没有下一篇了!
发表评论
用户名: 匿名