grid++json页面数据传入
Posted 蓬鹏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了grid++json页面数据传入相关的知识,希望对你有一定的参考价值。
最近遇到一个问题,就是要用Grid++做页面数据报表打印,但是翻了Grid++文档就是没有直接从页面上传数据的,都是要加载txt文档,填写txt文档的url。自己尝试直接页面上传JSON数据到Grid++控件中,竟然成功了,分享一下。
1.html页面代码如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>会员资料报表</title> <!--<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>--> <script src="CreateControl.js" type="text/javascript"></script> <script type="text/javascript"> function window_onload() { var Data = "{"Detail": [" + "{"ProductID": 2,"ProductName": "牛奶","UnitPrice": 15.2,"Quantity": 20,"Amount": 304}," + "{"ProductID": 16,"ProductName": "饼干","UnitPrice": 13.9,"Quantity": 35,"Amount": 486.5}," + "{"ProductID": 36,"ProductName": "鱿鱼","UnitPrice": 15.2,"Quantity": 25,"Amount": 380}," + "{"ProductID": 59,"ProductName": "苏澳奶酪","UnitPrice": 44,"Quantity": 30,"Amount": 1320}" + "]}"; var d = JSON.parse(Data); ReportViewer.Stop(); var Report = ReportViewer.Report; var Recordset = Report.DetailGrid.Recordset; Report.PrepareLoadData(); for(var i = 0; i < d.Detail.length; i++) { Recordset.Append(); Report.FieldByName("C1").AsString = d.Detail[i].ProductID; Report.FieldByName("C2").AsString = d.Detail[i].ProductName; Report.FieldByName("C3").AsString = d.Detail[i].UnitPrice; Report.FieldByName("C4").AsString = d.Detail[i].Quantity; Report.FieldByName("C5").AsString = d.Detail[i].Amount; Recordset.Post(); } ReportViewer.Start(); } </script> </head> <body onload="window_onload()"> <script type="text/javascript"> CreatePrintViewerEx("100%", "100%", "www.grf", "", true, ""); </script> </body> </html>
2.Grid++文件代码如下,txt保存改后缀为grf就可以:
{ "Version":"6.3.0.1", "Font":{ "Name":"宋体", "Size":90000, "Weight":400, "Charset":134 }, "Printer":{ }, "DetailGrid":{ "Recordset":{ "Field":[ { "Name":"C1" }, { "Name":"C2" }, { "Name":"C3" }, { "Name":"C4" }, { "Name":"C5" } ] }, "Column":[ { "Name":"Column1", "Width":2.38 }, { "Name":"Column2", "Width":2.38 }, { "Name":"Column3", "Width":2.38 }, { "Name":"Column4", "Width":2.38 }, { "Name":"Column5", "Width":2.38 } ], "ColumnContent":{ "Height":0.508, "ColumnContentCell":[ { "Column":"Column1", "DataField":"C1" }, { "Column":"Column2", "DataField":"C2" }, { "Column":"Column3", "DataField":"C3" }, { "Column":"Column4", "DataField":"C4" }, { "Column":"Column5", "DataField":"C5" } ] }, "ColumnTitle":{ "Height":0.508, "ColumnTitleCell":[ { "GroupTitle":false, "Column":"Column1", "TextAlign":"MiddleCenter", "Text":"ProductID" }, { "GroupTitle":false, "Column":"Column2", "TextAlign":"MiddleCenter", "Text":"ProductName" }, { "GroupTitle":false, "Column":"Column3", "TextAlign":"MiddleCenter", "Text":"UnitPrice" }, { "GroupTitle":false, "Column":"Column4", "TextAlign":"MiddleCenter", "Text":"Quantity" }, { "GroupTitle":false, "Column":"Column5", "TextAlign":"MiddleCenter", "Text":"Amount" } ] } }, "Parameter":[ { "Name":"ProductID" }, { "Name":"ProductName" }, { "Name":"UnitPrice" }, { "Name":"Quantity" }, { "Name":"Amount" } ], "ReportHeader":[ { "Name":"ReportHeader1", "Height":1.05833, "Control":[ { "Type":"StaticBox", "Name":"StaticBox1", "Left":5.79967, "Top":0.1905, "Width":2.794, "Height":0.804333, "Font":{ "Name":"宋体", "Size":156000, "Weight":400, "Charset":134 }, "Text":"会员集料" } ] } ] }
以上是关于grid++json页面数据传入的主要内容,如果未能解决你的问题,请参考以下文章
AJAX 响应:数据(JSON、XML)还是 HTML 片段? [关闭]
传入任意json数据源进行格式化处理并用Angularjs显示
[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def(代码片段