Take the 2-minute tour ×

I'm trying to create a column in jqgrid (latest version) and that column is a one to many relationship. For example, in view mode it should show State.Name, then in edit mode is should show a drop down with State.Name and taking the value of State.Id as id.

The information coming from the backend is:

    "rows":[{"Id":5,"Description":"City 1","State":{"Id":1,"Name":"California"}}],

I tried this without success:

name: 'State.Name', index: 'State.Id', editable: true, sortable: true, hidden: false, align: 'left', formatter: 'select',
edittype: "select", editrules: { required: true }, 
editoptions: {
        dataUrl: $("#ServiceUrlState").val(),
        buildSelect: function (data) {
            var response = jQuery.parseJSON(data);
            var html = '<select>';
            if (response && response.length) {
                for (var i = 0, l = response.length; i < l ; i++) {
                    var item = response[i];
                    html += '<option value="' + item.Id + '">' + item.Nombre + '</option>';
            return html + "</select>";

The value of ServiceUrlState is set in Index.cshtml (which ends in an html page) and is assigned with:

@Html.Hidden("ServiceUrlState", Url.RouteUrl("ApiControllerOnly", new { httproute = "", controller = "States" }))

I'm using ASPNET MVC 4, but the question should not be related to that.

I need something like...when in view mode...use the "State.Name" field to show, but when posting send the Id (and use StateId as the name on the posting)

What's wrong?

Thanks in advance! Guillermo

share|improve this question
It's not full clear what is your main problem, but the usage of dataUrl: $("#ServiceUrlState").val() is definitively wrong. When the value of $("#ServiceUrlState") will be filled? Could the value will be changed? Why it's needed to hold URL inside of DOM element on the page? –  Oleg Jan 17 '13 at 9:35
The is defined in the html page. I'll clarify it in the question –  polonskyg Jan 17 '13 at 12:02

Your Answer



Browse other questions tagged or ask your own question.