Duplicate rows after addRow()

I’m using a grid with a data processor in a Yii framework. My tables all have integer IDs with AUTOINCREMENT enabled.

After entering a new row in the grid, the data processor assigns the next available ID value, and everything seems to be OK. However, if I then edit the row, the update event triggers an additional duplicate row.

This is the result of the data processor log file:

[code]Log:
row 0 marked [inserted,valid]
Initiating data sending for all rows
Sending all data at once
Server url: ./index.php?r=Page/fetch_data&editing=true parameters
Server response received details
Action: inserted SID:0 TID:47
row 0 unmarked [updated,valid]
row 47 marked [updated,valid]
Initiating data sending for 47
Initiating data sending for all rows
Sending all data at once
Server url: ./index.php?r=Page/fetch_data&editing=true parameters
Server response received details

<?xml version='1.0' ?>

Action: inserted SID:47 TID:48
row 47 unmarked [updated,valid]
[/code]

Looking at the log, the initial insert operation returns the correct ID of 47. But the subsequent update is tagged as an “insert” event, and returns 48, leaving the database with two rows - 47 and 48.

This is the client-side code:

...
        var dataSourceGrid = dataSourceRoot + "fetch_data";
	grid1.load(dataSourceGrid);
	grid1.attachEvent("onRowSelect", doOngrid1Select);
	dp1 = new dataProcessor(dataSourceGrid);
	dp1.attachEvent("onAfterUpdate", function(sid, action, tid, xml){
		if (action == "invalid"){
			grid1.setCellTextStyle(sid, 2, "background:#eeaaaa");
			dhtmlx.message(xml.getAttribute("details"));
		} else {
			var actionType = xml.getAttribute("type");
			if (actionType == 'inserted') {
				grid1.selectCell(grid1.getRowIndex(tid),0,false,false,true);
			}
			statusBar1.setText(tableName + ' ' + tid + ' ' + actionType);
		}
	})
	dp1.init(grid1);
...

The idea is that, immediately after adding the new row, the user can edit the [name] field and add any other data as required.

This is the code around the addRow() operation:

function addRow(target){
	switch(target) {
		case 1:	//grid1
			var newName = prompt("Enter new " + tableName +" name:","New " + tableName);
			if(newName !== null) {
				grid1.addRow(0, [newName]);
			} else {
				statusBar1.setText("Cancelled - no data was added!");
			}
			break;
		default:
      }
  }

The PHP code looks like this:

...
$grid = new GridConnector($current_model, "PHPYii");
$grid->configure("-", "id", $column_ids);
$grid->render();

A workaround is to force a full page refresh i.e. location.reload() but then the user has to search for the new record to edit it.

Any suggestions gratefully received!

grid1.addRow(0, [newName]);

Please, note that it is not available to set the id of the row to “0”
Also, each row should have a unique id.