onSelectRow fix for jqGrid

I just love the jqGrid jQuery plugin. If you haven’t tried it out yet, perhaps you should?

Still, if you look up the online demos that describe how to edit a row, you may discover that the onSelectRow method used in the demos is not quite perfect. After editing a row, you must select a new one before you can edit the first one again.

I replaced the original onSelectRow method…

onSelectRow: function(id) {
   if (id && id!==lastsel) {
      jQuery('#rowed3').jqGrid('restoreRow',lastsel)
      jQuery('#rowed3').jqGrid('editRow',id,true);
      lastsel=id;
   }
}

…with this one…

onSelectRow: function(id) {
   if (id) {
      if (id !== lastsel) {
         articleGrid.jqGrid('restoreRow', lastsel);
         articleGrid.jqGrid('editRow', id, true);
         lastsel = id;
      } else {
         articleGrid.jqGrid('restoreRow', lastsel);
         lastsel = "";
      }
   }
}

…and now, the grid behaves a lot more like I want it to.

Advertisements