I’ve implemented a functioning jqgrid in MVC using a style similiar to:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'/Home/GridData/',
datatype: 'json',
mtype: 'GET',
colNames:['Id','Votes','Title'],
colModel :[
{name:'Id', index:'Id', width:40, align:'left' },
{name:'Votes', index:'Votes', width:40, align:'left' },
{name:'Title', index:'Title', width:200, align:'left'}],
pager: jQuery('#pager'),
rowNum:10,
rowList:[5,10,20,50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
});
});
</script>
from:
http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
Here it is implemented mainly in the View.
However when trying to solved a populating edit dropdownlist from database issue I found:
http://www.trirand.net/demoaspnetmvc.aspx
In this solution they seem to do most of the grid setup implementation in the controller.
I would like to know which is best maybe from a best practices viewpoint. Thanks!
jQuery is a JavaScript framework and jqGrid is made of jQuery.
So it should be handled in viewer. There is no way to handle jqGrid in controller technically.
But If you want to generate that in controller-side, you can generate that
in server-page dynamically.