0

I have a JQGrid with 3 columns. The third column, I want it as a dropdownlist based on some value in the second column. Is this Possible?

Also in the JQGrid demo, do add a dropdown we need to set the edittype to "select" and pass the values in JSON.

edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}},

My next question is how to pass values to this column from a model object in the format it is expecting.

tereško
  • 58,060
  • 25
  • 98
  • 150
Sid13
  • 1
  • 2
  • see [the answer](http://stackoverflow.com/a/17410568/315935) and [this one](http://stackoverflow.com/a/19427444/315935) which demonstrates how to use `beforeProcessing` to modify `editoptions.value` dynamically (using for example `setColProp`). – Oleg Dec 05 '14 at 06:01
  • public IEnumerable listCode { get; set; } – Sid13 Dec 11 '14 at 02:37
  • colNames: ['Column1','Column2','Status','Column4','Column5'], colModel: [ { name: 'Field1' }, { name: 'Field2' }, { name: 'Status' }, { name: 'Field4' }, { name: 'Field5', width: 80, search: false, // Want this either as a drop down or a text box based on value in "Status" column – Sid13 Dec 11 '14 at 02:42
  • If it is a dropdown then I want the dropdown to be populated from the below model object. public IEnumerable listCode { get; set; } Is there any example for the above? – Sid13 Dec 11 '14 at 02:43

1 Answers1

0

You can use dataUrl or postData property of editoption defined as function. See the answer or here and here. If you need to send standard URL parameters like /mySetectUrl?status=StatusValue then you can use

name: "Field5", edittype: "select",
editoptions: {
    // it produces URL like /mySetectUrl?status=StatusValue
    dataUrl: "/mySetectUrl",
    postData: function (rowid, value, name) {
        return { status: $(this).jqGrid("getCell", rowid, "Status") };
    }
}

If you need to construct some another URL like /mySetectUrl/StatusValue you can use dataUrl defined as function:

name: "Field5", edittype: "select",
editoptions: {
    // it produces URL like /mySetectUrl/StatusValue
    dataUrl: function (rowid, value, name) {
        return "/mySetectUrl/" +
            encodeURIComponent($(this).jqGrid("getCell", rowid, "Status"));
    }
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg, but the above gives me a dropdown, how about if I need a text box instead of dropdown based on the value. – Sid13 Dec 11 '14 at 14:48
  • @Sid13: You are welcome! What you want to do with the text box? It will be automatically filled with the value of the cell which you edit. You can use `dataInit` to make any other modification. – Oleg Dec 11 '14 at 15:02
  • Oleg, basically based on the value in the status field, I will either populate a dropdown which the user will select a value from OR I will just display a text with some information on it.Thanks – Sid13 Dec 11 '14 at 15:14
  • Also the text I want to display in the column should come from the server. Thanks – Sid13 Dec 11 '14 at 15:20