views:

1346

answers:

3

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 im 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.

A: 

Shouldnt your column model be [id, first, lastname] ? Anyway there is Phil Haack's post and I have one on enabling editing.

Morph
+2  A: 

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.

Craig Stuntz
Thanks a lot for the link, it helped a great deal my solution is now working and I will be able to play with it to see all of what is going on. Thanks for the great tutorial and break down of the info.
A: 

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.

solkim