开发者

Have jqGrid use different page to view a row

I'm writing a MVC website and using jqGrid. I have managed to get it working, loading data, editing via a different web page and deleting data.

However, I'm trying to figure out how to make it go to a different page when you click view. Currently it will display the row data in a model form. What I need to happen is for it to go to a different page e.g. /CLients/ViewClient/1

The reason for this is that the client model has more information than I'm displaying on the grid. Hence, I need to go to a separate page to display all t开发者_C百科he information in the correct manor.

Anyone got any idea on how I can do this?


what I did was override the 'onSelectRow' event handler:

$("TABLE.jqGrid").jqGrid({
    url: '/Widgets/Get',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['Id', 'Type', 'Name'],
    colModel: [
            { name: 'Id', index: 'Id', width: 50 },
            { name: 'Type', index: 'GameType', width: 100 },
            { name: 'Name', index: 'Name', width: 150 },
        ],
    pager: '#pager',
    rowNum: 25,
    rowList: [25, 50, 100],
    sortname: 'Name',
    viewrecords: true,
    altRows: true,
    gridview: true,
    height: 'auto',
    onSelectRow: function(id)
    {
        document.location.href = '/Widgets/Show/' + id;
    }
});

you can replace the hardcoded URLs with <%= Url.Action("Whatever") %>


Probably it would be better if you change a little the logic with filling the data in your view used jqGrid.

You can do something like following:

  • create an action in you controller for jqGrid which will give back only a page of data. You gave the data back in JSON format. The number of rows per page and the page needed you will receive as parameters of the MVC action.
  • in the view where you use jqGrid you should don't fill any data. Instead of that you set the datatype parameter as "json" and the url parameter of jqGrid as the URL of the action which provide the paged data back. Then jqGrid will fill the data per AJAX. After user will click on the next page a new request will be send to the server (to the corresponding action in you controller). The number of page requested will be send as a parameter to the action.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜