views:

27

answers:

2

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 the information in the correct manor.

Anyone got any idea on how I can do this?

A: 

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.
Oleg
I have it paging already and that works. The issue is that when I show the grid I'm only showing Name, Fax, Phone. However, the client object contains the following data (not it all)NameFaxTelAddress (address object)Contacts (IList<Contact>)ParentCompany (parent company object)As you can see this is far too much data to show in a grid. Hence, I want to be able to view this information on a separate page rather than on the grid. So when the user selects a row of data (client data), and clicks on the view button. They are taken to a new page where I can show all the client data
Tanzy
You can implement this inside of `onSelectRow` event (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events). You can for example set window.location to the new value, open a new window or tab or just show the details of selected row under the grid (with respect of AJAX request). I prefer showing details under the grid. Sometime I create hidden columns with the additional informations (like Tel Address, ParentCompany) and set inside of `loadComplete` event tooltips (setting 'title' attribute with `setCell` method). So if user goes with the cursor over Name column it sees Fax, Tel etc.
Oleg
+1  A: 

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") %>

dave thieben
That does the trick. Must admit it would be nicer to be able to change the behaviour of the view button
Tanzy
@Tanzy: to change the behavior of the view button you can add custom button (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons) with `caption:""` and `buttonicon:"ui-icon-document"`. Then the button will looks like the view button. In `onClickButton` event you can implement any behavior you need.
Oleg