我正在尝试使用N层架构中的数据库填充jqGrid。我已经彻底查看了jqGrid代码和文档。我需要另一组眼睛来查看下面的代码并告诉我是否遗漏了某些东西。
正如您在代码中看到的那样,我将网格设置为在页面加载或刷新期间加载。网格加载后,我进行Ajax调用以获取JSON数据(再次)并显示在网格下方的div中。
我看到了大部分预期的行为。页面加载后,网格显示加载指示符,然后启动Ajax调用,并在网格下方显示JSON数据。问题是网格完全是空的。列标题是正确的,但网格主体中没有数据。
var mydata;
$(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”,资格:“MCA”,YearOfPass:“2012”,百分比:“74.9”,技术:“。Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”, EmailId:“kolla.ganapathirao@gmail.com”,MobileNo:“8985689317”}, // {TraineeName:“Guptha”,资格:“B.Tech”,YearOfPass:“2012”,百分比:“90”,技术:“。Net”,技能:“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”,资格:“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”,资格:“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 spring struts”,BatchName:“11”,EmailId :“vasntha@gmail.com”,MobileNo:“8985689311”}, // {TraineeName:“Vasantha”,资格:“B.Tech”,YearOfPass:“2012”,百分比:“76”,技术:“。Net”,技能:“j2EE j2SEE”,BatchName:“11”,EmailId :“narendra@gmail.com”,MobileNo:“8985689310”}, // {TraineeName:“Narendra”,资格:“MCA”,YearOfPass:“2010”,百分比:“73.9”,技术:“Java”,技能:“Asp,Mvc,Wcf”,BatchName:“11”,EmailId :“kolla.ganapathirao@gmail.com”,MobileNo:“8985689309”}, // {TraineeName:“Praveen”,资格:“B.Tech”,YearOfPass:“2012”,百分比:“74.9”,技术:“。Net”,技能:“Asp,Mvc,Wcf”,BatchName:“11 “,EmailId:”gannipraveen@gmail.com“,MobileNo:”8985689308“}, // {TraineeName:“Dhanjay”,资格:“MCA”,YearOfPass:“2012”,百分比:“79”,技术:“。Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”, EmailId:“dhanjay@gmail.com”,MobileNo:“8985689307”}, // {TraineeName:“Gowrinaidu”,资格:“MCA”,YearOfPass:“2012”,百分比:“74.9”,技术:“。Net”,技能:“Asp,Mvc,Wcf”,BatchName:“12”, EmailId:“gowrinaidu@gmail.com”,MobileNo:“8985689306”}, // {TraineeName:“Swarup”,资格:“B.Tech”,YearOfPass:“2012”,百分比:“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]);
});