i’m trying to use jQuery multiselect plugin in a form editing jqGrid (add form).
This is the code (colModel extract) I’m using to build the dropdown:
{
name: 'CaratteristicheCamera',
index: 'CaratteristicheCamera',
width: 50,
hidden: true,
edittype: 'select',
editable: true,
editrules: { edithidden: true, required: true },
editoptions: {
multiselect: true,
dataUrl: '<%# ResolveUrl("~/Service/Domain/ServiceRoom.asmx/GetRoomFeatureList") %>',
buildSelect: function (data) {
var retValue = $.parseJSON(data);
var response = $.parseJSON(retValue.d);
var s = '<select id="CaratteristicheCamera" name="CaratteristicheCamera">';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
s += '<option value="' + response[i]["Id"] + '">' +
response[i]["Descrizione"] + '</option>';
}
}
return s + "</select>";
},
dataInit: function() {
$("#CaratteristicheCamera").multiselect();
}
}
},
As you guys can see, jqGrid call webmethod placed in asmx file. Everything seems to work ok, but I can’t receive all the values user select from the dropdown. It seems that the system send to the server the last selection.
Do u have any tips on it?
EDIT: this is the asmx webservice declaration
[WebMethod]
public string SaveRoom(string id, string codice, string Numero, string NumeroPiano,
string Nome, string TipoCamera, string StatoCamera,
string CaratteristicheCamera, string TipoSdoppiabilita)
{}
I tried Eric Hynds jQuery UI MultiSelect Widget together with jqGrid 3.4.1 and couldn’t see any problem which you described. I recommend you compare your demo with my to find the differences.
One bad thing which I see in your code is that you set
id="CaratteristicheCamera"attribute on the<select>which you generate inbuildSelect. You should just use<select>without any additional attributes. The jqGrid will set itself all attributes likeidormultiple="multiple".In the demo I used
editurl: 'test.asmx/dummy'which not exist on the server. So one sees the error message likeafter choosing and submitting the selected items
Nevertheless one can see with respect of tools like Fiddler, Firebug or Developer Tools of IE or Chrome (see HTTP traffic in “Network” tab) that the demo post the data like
to the
http://www.ok-soft-gmbh.com/jqGrid/test.asmx/dummy. So the values"FE,TN"of selected itemsFedEx, TNTwill be send as expected. In your case theCaratteristicheCameraparameter ofSaveRoomshould be initialized to the comma separated list of selected values. I hope you will find the problem in your code if you compare my demo with youth.Another small problem in the code which you posted is that you make serialization to JSON manually in the
WebMethodGetRoomFeatureListand returnsstring. So the string will be serialized to JSON twice. So you useCorrect will be to return something like
List<Room>. ASP.NET will serialize it automatically. If you would use the jqGrid optionthe
datainbuildSelectwill be not needed to parsed at all. You can directly usedata.d[i].Idanddata.d[i].Descrizionein the loop. I wrone you about the same problem in another answer on your old question.