Forum



19:13

20/04/2011

I am trying jqgrid for the first time in MVC. I have created a Controller(with hard coded json string), View. Grid is appearing but the data is not getting displyed in the grid. Is there any working example/demo/code or what could be the issue in my code. Pl help.
View:
<table id="list2"></table>
<div id="pager2"></div>
<script type="text/javascript">
jQuery("#list2").jqGrid({
url: '/Json1/GetJsonGridData/',
dataType: "json",
colNames: ['ProductID', 'Name', 'ProductNumber', 'Color', 'Size', 'Style'],
colModel: [{ name: 'ProductID', index: 'ProductID', width: 150, align: 'left' },
{ name: 'Name', index: 'Name', width: 150, align: 'left' },
{ name: 'ProductNumber', index: 'ProductNumber', width: 150, align: 'left' },
{ name: 'Color', index: 'Color', width: 150, align: 'left' },
{ name: 'Size', index: 'Size', width: 150, align: 'left' },
{ name: 'Style', index: 'Style', width: 150, align: 'left' }
],
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'ProductID',
pager: '#pager2',
sortorder: "desc",
viewrecords: true,
caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
</script>
Controller (Json1):
public string GetJsonGridData()
{
List<Product> personList = ProductRepository.GetProducts();
string productJqGridView = @"
{
total: '1',
page: '10',
records: '10',
rows :
[
{
id:'1', cell:[ '1', 'Coke', 'Abc100', 'Red', 's', 'Fasion' ]
},
{
id:'2', cell:[ '2', 'Pepsi', 'Abc200', 'blue', 'xl', 'B' ]
},
{
id:'3', cell:[ '3', 'LP', 'Abc300', 'green', 'l', 'D' ]
},
{
id:'4', cell:[ '4', 'AB', 'Abc400', 'purple', 'xxl', 'D' ]
},
{
id:'5', cell:[ '5', 'All Star', 'Abc500', 'black', 's', 'H' ]
},
{
id:'6', cell:[ '6', 'Wai', 'Abc600', 'yellow', 's', 'G' ]
},
{
id:'7', cell:[ '7', 'cd', 'Abc700', 'pink', 's', 'C' ]
},
{
id:'8', cell:[ '8', 'LV', 'Abc800', 'blue', 's', 'G' ]
},
{
id:'9', cell:[ '9', 'DD', 'Abc900', 'grey', 's', 'D' ]
},
{
id:'10', cell:[ '10', 'aW', 'Abc1000', 'silver', 'm', 'L' ]
}
]
}";
return productJqGridView;
}
20:13

10/08/2009

You can for example download the example created for the asnwer. This example is the modification of the Phil Haack demo.
Best regards
Oleg
20:55

20/04/2011

OlegK said:
You can for example download the example created for the asnwer. This example is the modification of the Phil Haack demo.
Best regards
Oleg
Oleg,
Thanks so much for the reply and a pointer to the code sample. After I have downloaded the zip file, I am not able to open the solution file "says the current installation does not support". I have 2008 and 2010 Visual studio. But any way, I looked at the code. It looks like the sorting, paging and filtering are happening on the server side code in the controller.
I want to do my grid as below.
1. I will just create the JSON formatted data in the controller.
2. Supply this json data to jqgrid --> js version of jqgrid as in my first code sample. (I don't want to use jqgrid for MVC from trirand which is server side componet)
3. And use the jqgrid out of the box capabilities for sorting, paging, filtering.
If there is any working example with this scenario would you pl provide.
Is it achievable something like this. I tried the array data version from trirand samples. it looks good. sorting, paging is working with out writing any code.
But I am trying using JSON data. Not bale to make it work.
Thanks again for your valuble time.
Thanks,
Most Users Ever Online: 715
Currently Online:
70 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66