在动态jqgrid

时间:2016-01-29 08:47:51

标签: dynamic jqgrid

    $(document).ready(function () {
        $.ajax({
            url: "/GridTest/getTestData",
            datatype: "json",
            type: "POST",
            async: false,
            success: function (result) {
                $("#dataGrid").jqGrid({
                    datatype: 'jsonstring',
                    data: result,
                    gridview: true,
                    colModel: result,
                    height: "auto",
                    loadComplete: function (data) {
                        alert('loaded');
                    },
                    loadError: function (xhr, status, error) {
                        alert('error');
                    }
                });
            },
            error: function (x, e) {
                alert(x.readyState + " " + x.status + " " + e.msg);
            }
        });
    });

        string result = "['Id', 'First Name', 'Last Name', 'Last 4 SSN', 'Department', 'Age', 'Salary', 'Address', 'Marital Status']";

您好,

我在动态jqgrid中显示json数据时遇到问题。我在服务器端使用这个json字符串,并在ajax函数中将列名和数据设置为此字符串.Grid正在加载但在页面上没有显示任何内容。我尝试了很多替代方案,但无法在jqgrid中显示json数据。我的方式出了什么问题? 提前致谢

1 个答案:

答案 0 :(得分:0)

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/css/ui.jqgrid.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.base.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.common.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.formedit.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.inlinedit.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.celledit.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.subgrid.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.treegrid.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.grouping.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.custom.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/jquery.fmatter.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/jquery.searchFilter.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.jqueryui.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/jqDnR.js"></script>
<!--<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/jquery.jqGrid.min.js"></script>-->

        $.ajax({
            type: "POST",
            //url: "../DynamicColumnBinding.txt",
            url: "/GridTest/getTestData",
            dataType: "json",
            async: false,
            success: function (result) {
                var colD = result.couponStripList,
                    colM = result.colModelList;

                alert(typeof(result));
                $("#dataGrid").jqGrid({
                    datatype: 'local',
                    data: colD.rootVar,
                    gridview: true,
                    colModel: colM,
                    height: "auto",
                    loadComplete: function (data) {
                        alert('loaded');
                    },
                    loadError: function (xhr, status, error) {
                        alert('error');
                    }
                });
            },
            error: function (x, e) {
                alert(x.readyState + " " + x.status + " " + e.msg);
            }
        });
    });


        string dataFile = System.IO.File.ReadAllText(Server.MapPath("~/DynamicColumnBinding.txt"));
        jss.Serialize(text);
        return Json(dataFile, JsonRequestBehavior.AllowGet);