Herb Caudill
Herb Caudill

Reputation: 49952

Can I change the primary ID of a row in JQGrid without reloading?

I'm trying to implement inline inserting in a JQGrid. My approach thus far is:

Suprisingly, this rube goldberg scheme works pretty well. To make it seamless, though, I'd like to silently update the ID of the row that was just added, so that the user can continue to edit the other columns. I'd rather not do a grid.trigger("reloadGrid"), because I lose focus on that row.

I've tried

grid.setRowData(-1, { MyPrimaryKeyField: newID });

but that doesn't work (it still thinks the row's ID is -1). Is there an easy way to change the primary ID of a row without reloading the whole grid?

Upvotes: 7

Views: 3182

Answers (2)

Søren
Søren

Reputation: 6787

Actually you can't change grids primary row Id by "setRowData", but there is a simple way to do it :

$("#-1").attr('id',newId);

;-)

Upvotes: 7

Justin Ethier
Justin Ethier

Reputation: 134167

You could work around this by making an AJAX call to do the insert and return the new ID. Once you have the ID, call reloadGrid and then select the row using the newly returned ID. You would want to also put up a spinner while you are doing this so the user knows your page is busy. Not quite what you are asking for but it should meet your needs.

Upvotes: 2

Related Questions