1

我正在尝试用 N 层架构中的数据库中的数据填充 jqGrid。我已经彻底查看了 jqGrid 代码和文档。我需要另一双眼睛来查看下面的代码并告诉我是否遗漏了什么。

正如您将在代码中看到的,我将网格设置为在页面加载或刷新期间加载。网格加载后,我进行 Ajax 调用以获取 JSON 数据(再次)并显示在网格下方的 div 中。

我看到了大部分预期的行为。页面加载后,网格显示加载指示器,然后启动 Ajax 调用,JSON 数据显示在网格下方。问题是网格完全是空的。列标题正确,但网格正文中未显示任何数据。

变量我的数据;

    $(document).ready(function () {

        var nn = "nilesh";

        $.ajax(

            {
                type: "POST",
                url: "SearchandViewTraineeProfiles.aspx/GetTrainee",
                data: "{'name': '" + nn + "'}",
                contentType: "application/json; charset=utf-8",
                dataType:'text',
                success:
                    function (data) {

                        mydata = data;
                        alert(data);


                    },
                error:
                    function () {

                        alert("error occured");

                    }

            }


            );

    });


</script>

//这个函数用于显示表格布局

$(document).ready(function () {



    jQuery("#list1").jqGrid({
        datatype: "text",
        //            colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
        colNames: ['TraineeName', 'Qualification', 'YearOfPass', 'Percentage', 'Technology', 'Skills', 'BatchName', 'EmailId', 'MobileNo'],
        //            colModel: [
        //                  { name: 'id', index: 'id', width: 60, sorttype: "int" },
        //                  { name: 'invdate', index: 'invdate', width: 90, sorttype: "date" },
        //                  { name: 'name', index: 'name', width: 100 },
        //                  { name: 'amount', index: 'amount', width: 80, align: "right", sorttype: "float" },
        //                  { name: 'tax', index: 'tax', width: 80, align: "right", sorttype: "float" },
        //                  { name: 'total', index: 'total', width: 80, align: "right", sorttype: "float" },
        //                  { name: 'note', index: 'note', width: 150, sortable: false }
        //              ],
        colModel: [
            { name: 'TraineeName', index: 'TraineeName', width: 60, sorttype: "string" },
            { name: 'Qualification', index: 'Qualification', width: 90, sorttype: "string" },
            { name: 'YearOfPass', index: 'YearOfPass', width: 100, sorttype: "int" },
            { name: 'Percentage', index: 'Percentage', width: 80, align: "right", sorttype: "float" },
            { name: 'Technology', index: 'Technology', width: 80, align: "right", sorttype: "string" },
            { name: 'Skills', index: 'Skills', width: 80, align: "right", sorttype: "string" },
            { name: 'BatchName', index: 'BatchName', width: 150, sorttype: "string" },
            { name: 'EmailId', index: 'EmailId', width: 150, sortable: false },
            { name: 'MobileNo', index: 'MobileNo', width: 150, sortable: false },
        ],
        multiselect: true,
        rowNum: 10,
        rowList: [5, 10, 20, 50, 100],
        pager: jQuery('#pager1'),
        sortorder: "desc",
        viewrecords: true,
        caption: "TraineeProfiles"
    });
    jQuery("#list1").jqGrid('navGrid', '#pager1', { del: false, add: false, edit: false }, {}, {}, {}, { multipleSearch: true });




   // takeing the data from user or database

// var mydata = [ // { TraineeName: "Ganapathi", Qualification: "MCA", YearOfPass: "2012", Percentage: "74.9", Technology: ".Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "kolla.ganapathirao@gmail.com", MobileNo: "8985689317" }, // { TraineeName: "Guptha", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "90", Technology: ".Net", Skills: "Asp,Mvc,Wcf,Ajax", BatchName: "12", EmailId: "guptha@gmail.com", MobileNo: "8985689316" }, // { TraineeName :“Raju”,资格:“B.Tech”,YearOfPass:“2010”,百分比:“64.9”,技术:“.Net”,技能:“Asp,Mvc,Wcf", BatchName: "12", EmailId: "raju@gmail.com", MobileNo: "8985689315" }, // { TraineeName: "Devashish", Qualification: "B.Tech", YearOfPass: " 2012”,百分比:“70.9”,技术:“.Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”,EmailId:“crucut@gmail.com”,MobileNo:“8985689314”},/ / { TraineeName:“Kalyan”,资格:“B.Tech”,YearOfPass:“2011”,百分比:“78”,技术:“.Net”,技能:“Asp Mvc Wcf”,BatchName:“12”,EmailId : "kalyan@gmail.com", MobileNo: "8985689313" }, // { TraineeName: "Vijay", Qualification: "MCA", YearOfPass: "2011",百分比:“79”,技术:“.Net”,技能:“Asp Mvc Wcf”,BatchName:“11”,EmailId:“ganagaraju@gmail.com”,MobileNo:“8985689312”},// { TraineeName:“ Gangaraju”,资格:“B.Tech”,YearOfPass:“2011”,百分比:“74.9”,技术:“java”,技能:“jsp springs struts”,BatchName:“11”,EmailId:“vasntha@gmail。 com", MobileNo: "8985689311" }, // { TraineeName: "Vasantha", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "76", Technology: ".Net", Skills: "j2EE j2SEE”,BatchName:“11”,EmailId:“narendra@gmail.com”,MobileNo:“8985689310”},// { TraineeName: "Narendra", Qualification: "MCA", YearOfPass: "2010", Percentage: "73.9", Technology: "Java", Skills: "Asp,Mvc,Wcf", BatchName: "11", EmailId : "kolla.ganapathirao@gmail.com", MobileNo: "8985689309" }, // { TraineeName: "Praveen", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "74.9", Technology: " .Net", Skills: "Asp,Mvc,Wcf", BatchName: "11", EmailId: "gannipraveen@gmail.com", MobileNo: "8985689308" }, // { TraineeName: "Dhanjay", Qualification: "MCA ", YearOfPass: "2012", Percentage: "79", Technology: ".Net", Skills: "Asp,Mvc,Wcf",BatchName: "12", EmailId: "dhanjay@gmail.com", MobileNo: "8985689307" }, // { TraineeName: "Gowrinaidu", Qualification: "MCA", YearOfPass: "2012", Percentage: "74.9",技术:“.Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”,EmailId:“gowrinaidu@gmail.com”,MobileNo:“8985689306”},// { TraineeName:“Swarup”,资格: "B.Tech", YearOfPass: "2012", Percentage: "59.9", Technology: ".Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "swarup@gmail.com ", 手机号: "8985689305" }, // ];// { TraineeName: "Gowrinaidu", Qualification: "MCA", YearOfPass: "2012", Percentage: "74.9", Technology: ".Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "gowrinaidu@gmail.com", MobileNo: "8985689306" }, // { TraineeName: "Swarup", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "59.9", Technology: ". Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "swarup@gmail.com", MobileNo: "8985689305" }, // ];// { TraineeName: "Gowrinaidu", Qualification: "MCA", YearOfPass: "2012", Percentage: "74.9", Technology: ".Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "gowrinaidu@gmail.com", MobileNo: "8985689306" }, // { TraineeName: "Swarup", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "59.9", Technology: ". Net", Skills: "Asp,Mvc,Wcf", BatchName: "12", EmailId: "swarup@gmail.com", MobileNo: "8985689305" }, // ];"12", EmailId: "gowrinaidu@gmail.com", MobileNo: "8985689306" }, // { TraineeName: "Swarup", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "59.9",技术:“.Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”,EmailId:“swarup@gmail.com”,MobileNo:“8985689305”},//];"12", EmailId: "gowrinaidu@gmail.com", MobileNo: "8985689306" }, // { TraineeName: "Swarup", Qualification: "B.Tech", YearOfPass: "2012", Percentage: "59.9",技术:“.Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”,EmailId:“swarup@gmail.com”,MobileNo:“8985689305”},//];

    for (var i = 0; i <= mydata.length; i++)
        jQuery("#list1").jqGrid('addRowData', i + 1, mydata[i]);



});
4

0 回答 0