سؤال

I have defined a select in a jqgrid table as follows:

{name: 'station', index: 'station', editable: true, width: 60,
  edittype:"select", defaultValue:"",
  editoptions:{
         dataUrl: "getStationList"
  },
  editrules: { required: true }
},

The getStationList returns something like:

<select>
<option value="id1">Station1</option>
<option value="id2">Station2</option>
</select>

With the current definition, the first time the combo is shown, the list of Station appears nicely (Station1, Station2,...) and the JSON contains "id1" when Station1 is selected. But when the table updates it displays "id1" in the select combo instead of keeping showing the Station's list.

Is that a bug or I`m missing some configuration option? (probably the last)

Thanks!

هل كانت مفيدة؟

المحلول

I think you have already a problem during filling the grid. If you want to use ids instead of names you should use formatter: "select" additionally to edittype:'select' (see the documentation). In the case you will have to place ids in the grid during filling of the grid with data. I mean that input data for jqGrid sould contains id1 and id2 instead of "Station1" and "Station2". Only in the case you will be able to use dataUrl which provide <option value="id1">Station1</option>. The next problem is: you have to set editoptions.value or formatoptions.value instead of usage dataUrl: "getStationList". So the usage of formatter: "select" is relatively complex. What one can do is to send the data like {"id1":"Station1", "id2":"Station2"} as a part of main grid data. One can place {stations: {"id1":"Station1", "id2":"Station2"}} as userdata part of JSON input (see the documentation). Inside of beforeProcessing callback one could set formatoptions.value based of userdata.stations. In the way one would de facto make request to getStationList not only during editing of data, but additionally during every filling of grid.

I personally prefer to use no formatter: "select" and use selects in the form

<select>
    <option value="Station1">Station1</option>
    <option value="Station2">Station2</option>
</select>

In the way the client code would "know" nothing about implementation details of the representation of data. One would fill grid with the data "Station1" and "Station2" and send the same data during editing of grid. The server on the other side will get ids by the names whenever it's needed. Typically if I create "lookup" table Stations with column like "Id" and "Name" I would set

CONSTRAINT UC_Stations_Name UNIQUE NONCLUSTERED (Name ASC)

So there are unique index in the table which can get Id by Name. In the way all Update statements with Name are exactly so quickly as with Id. I use Id in all internal SQL statements, but send only Name to external source. In the way I don't need use formatter: "select".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top