Reputation:
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.
My js code is as follows:
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?
Could someone point to a reference that is straight forward or just start me off with this I would be most grateful.
Upvotes: 2
Views: 2437
Reputation: 99
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"]]
the first field in the JSON is the id, right? The second is the 'First Name' and the third should be 'MI', so on.
Upvotes: 0
Reputation: 126547
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.
Upvotes: 3
Reputation: 1719
Shouldnt your column model be [id, first, lastname] ? Anyway there is Phil Haack's post and I have one on enabling editing.
Upvotes: 0