Cómo actualizar la identificación de la fila jqgrid después de guardar mediante el botón de guardar de la acción del formateador

jqGrid edited row id needs to be refreshed after save from id returned in response. I tried code below but undefined message box appears.

How to update row id ? How to get response text after row is updated by Save action button ?


  colModel: [{name:_actions,width:45,
     onSuccess:function (rowID, response) {
      $("#" + rowID).attr("id", response.responseText);

    onEdit: function (rowID) {
     if (typeof (lastSelectedRow) !== 'undefined' && rowID !== lastSelectedRow)
       lastSelectedRow = rowID;

preguntado el 27 de agosto de 11 a las 19:08

1 Respuestas

I don't want to go back to our old discussion, but I just want to remind that the changing of id is not good practice.

You can try to solve the problem by placing of $("#" + rowID).attr("id", response.responseText); dentro de setTimeout. In the case the changing will be done after processing of the old id in inline editing code.

Moreover you could verify the following. In can be important to rename id in some other places saved by jqGrid internally. For example, selrow y selarrrow where the ids of selected rows will be hold.

Respondido 28 ago 11, 00:08

Major issue is that action buttons do not have single event where both old rowid and response text are passed like in inline edit aftersavefunc. I solved this by storing reponse to global variable in onSuccess =function (jqXHR) { actionresponse = jqXHR; return true; }" and used this in afterSave =function (rowID) { aftersavefunc(rowID,actionresponse)}. Db scheme uses natural primary key ids and is deployed to thousands of sites. Changing this even creating duplicate surrogate ids as you reccommended is too much work since requires rewriting number of production applications. - Andrus

@Andrus: OK, I understand that in case of many old version of your software installed the update scenario could be complex. I didn't thought about the problem. Nevertheless what I suggested you are not changing the primary key of the existing tables. I suggested to add an adicional column in tables where AUTOINCREMENT value could be saved. After that you could place UNIQUE CONSTRAINT or just an INDEX on the column to have quick search by the value from the column and use the value as id only for jqGrid. In your other applications you can continue to use old primary key. It should work - Oleg

@Andrus: You should be careful with saving jqXHR somewhere. You should write the code so that the pointer will be assigned to null if it is not used. If you will don't do this you could have memory leeks because the memory for jqXHR could not be released. - Oleg

Thank you. empty row is added in loadComplete. If this row is saved in inline edit, jqGrid row id needs to be updated from server response. So this issue occurs also if integer primary key is used. After I removed jqID() call from your other sample it looks like natural primary keys work OK with jqGrid without changing schema. I added actionresponse=null to afterSave handler. Hopefully this prevents leak. - Andrus

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.