Here is my dilemma,
这是我的困境,
I have not been able to manipulate my data to a form fitting to jqgrid
standards. This is my first time using the jqgrid
and I've spent a lot of time reading up on it.
我无法将数据操作为符合jqgrid标准的表单。这是我第一次使用jqgrid,我花了很多时间阅读它。
My js code is as follows:
我的js代码如下:
jQuery("#list").jqGrid({
url: '/Home/ListContacts/',
dataType: "json",
contentType: "application/json; charset=utf-8",
mtype: 'POST',
colNames: ['First Name', 'MI', 'Last Name'],
colModel: [{
name: 'First Name',
index: 'FName',
width: 40,
align: 'left'
},
{
name: 'MI',
index: 'MInitial',
width: 40,
align: 'left'
},
{
name: 'Last Name',
index: 'LName',
width: 400,
align: 'left'
}
],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
repeatitems: false,
viewrecords: true,
imgpath: '/scripts/themes/basic/images',
caption: 'My first grid'
});
What I'm getting from the database:
我从数据库中获得的内容:
[
["4", "Jenna", "Mccarthy"],
["56", "wer", "weoiru"]
]
Now correct me if I am wrong, but the index: in my colModel refers to the column names in my database right?
现在纠正我,如果我错了,但索引:在我的colModel中引用我的数据库中的列名对吗?
Could someone point to a reference that is straight forward or just start me off with this I would be most grateful.
有人可以指出一个直接的参考,或者只是让我开始,我会非常感激。
3 个解决方案
#1
Index is what will be passed to the controller in the sidx query string parameter to indicate which column should be used for sorting when you click on that column header in the grid. Name is the property name in the returned json for the data for that column. For obvious reasons, these are often the same. I have a long series of posts, starting here, which explains all of this in great detail.
索引是在sidx查询字符串参数中传递给控制器的,用于指示在单击网格中的列标题时应使用哪个列进行排序。 Name是返回的json中该列数据的属性名称。出于显而易见的原因,这些通常是相同的。从这里开始,我有一系列的帖子,这些都非常详细地解释了所有这些。
#2
Shouldnt your column model be [id, first, lastname] ? Anyway there is Phil Haack's post and I have one on enabling editing.
您的列模型不应该是[id,first,lastname]吗?无论如何有菲尔哈克的帖子,我有一个关于启用编辑。
#3
I can see that you have the 'First Name' and 'Last Name'. The column 'MI' is missing in your JSON-data what im getting from the database: [["4","Jenna","Mccarthy"],["56","wer","weoiru"]]
我可以看到你有'名字'和'姓氏'。我的JSON数据中缺少“MI”列从数据库获取的内容:[[“4”,“Jenna”,“Mccarthy”],[“56”,“wer”,“weoiru”]]
the first field in the JSON is the id, right? The second is the 'First Name' and the third should be 'MI', so on.
JSON中的第一个字段是id,对吧?第二个是'名字',第三个应该是'MI',依此类推。
#1
Index is what will be passed to the controller in the sidx query string parameter to indicate which column should be used for sorting when you click on that column header in the grid. Name is the property name in the returned json for the data for that column. For obvious reasons, these are often the same. I have a long series of posts, starting here, which explains all of this in great detail.
索引是在sidx查询字符串参数中传递给控制器的,用于指示在单击网格中的列标题时应使用哪个列进行排序。 Name是返回的json中该列数据的属性名称。出于显而易见的原因,这些通常是相同的。从这里开始,我有一系列的帖子,这些都非常详细地解释了所有这些。
#2
Shouldnt your column model be [id, first, lastname] ? Anyway there is Phil Haack's post and I have one on enabling editing.
您的列模型不应该是[id,first,lastname]吗?无论如何有菲尔哈克的帖子,我有一个关于启用编辑。
#3
I can see that you have the 'First Name' and 'Last Name'. The column 'MI' is missing in your JSON-data what im getting from the database: [["4","Jenna","Mccarthy"],["56","wer","weoiru"]]
我可以看到你有'名字'和'姓氏'。我的JSON数据中缺少“MI”列从数据库获取的内容:[[“4”,“Jenna”,“Mccarthy”],[“56”,“wer”,“weoiru”]]
the first field in the JSON is the id, right? The second is the 'First Name' and the third should be 'MI', so on.
JSON中的第一个字段是id,对吧?第二个是'名字',第三个应该是'MI',依此类推。