PDA

View Full Version : [SOLVED] Store.commitChanges chokes on modified records that have been removed


tbarstow
07-20-2007, 11:49 AM
I have a data store where I add a record, modify it, then remove it. Calling commitChanges gives the following error:

Index or size is negative or greater than the allowed amount" code: "1
[Break on this error] return this.getLockedTable().rows[index];

I'm in Firefox, but it's an array indexing problem. The error is thrown in GridView.getLockedRow(). index is being passed as -1.

This may be related to a separate problem that I've noticed: Ext.data.Store.getModifiedRecords() seems to return records that have been removed.

mystix
07-20-2007, 02:13 PM
i have to nag once more... sigh :s

http://extjs.com/forum/showthread.php?t=8887

tbarstow
07-20-2007, 03:29 PM
sorry about that.

- the error message above is from Firebug with ext-all-debug.js, and no stack trace was provided.
- Ext 1.0.1a or 1.1RC1 - same problem
- YUI 2.2.0 + adapter
- Firefox 2.0.0.5 on a Mac

Here's an example that illustrates the bug:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>ext bug example</title>
<link rel="stylesheet" type="text/css" href="http://lhcommon/ext/1.1-rc1/resources/css/ext-all.css"></link>
<script type="text/javascript" src="http://lhcommon/ext/1.1-rc1/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="http://lhcommon/ext/1.1-rc1/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="http://lhcommon/ext/1.1-rc1/ext-all-debug.js"></script>
<script type="text/javascript">
Ext.onReady(function(){

var RecordType = Ext.data.Record.create(['name']);
var ds = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy([ ]),
reader: new Ext.data.ArrayReader({
id: '1'
}, RecordType)
});

var cm = new Ext.grid.ColumnModel([
{
dataIndex: 'name',
header: 'Name',
width: 100,
editor: new Ext.grid.GridEditor(new Ext.form.TextField())
}
]);

var ct = Ext.get('grid-ct');
ct.setWidth(300);
ct.setStyle({border: '1px solid #99bbe8', margin: '10px'});

var grid = new Ext.grid.EditorGrid(ct, {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel()
});
grid.render();

var gridHead = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(gridHead, [
{
text: 'Add Record',
handler: function() {
var rec = new RecordType({name:''}, ds.getCount()+1);
grid.stopEditing();
ds.insert(0, rec);
grid.startEditing(0, 0);
}
},
{
text: 'Remove Record',
handler: function() {
var rec = grid.getSelectionModel().getSelected();
ds.remove(rec);
}
},
{
text: 'Commit Changes',
handler: function() {
ds.commitChanges();
}
}
]);

});
</script>
</head>

<body>
<div id="grid-ct"></div>
</body>
</html>


Steps to reproduce using this example:

1. Click "Add Record"
2. Modify the name
3. Blur the name field
4. Select the row that you just added
5. Click "Remove Record"
6. Click "Commit Changes"

Thanks for your help. I tried debugging this myself but didn't get to the bottom of it. See original post for a couple of tips.

jack.slocum
07-20-2007, 11:53 PM
Before removing a record, you will need to either commit or reject changes. It's pretty simple to do, commit and reject are right on the record and there is a dirty flag as well.

If that is not desirable, you can also splice it out of the modified records array when you delete it.

FYI - I understand you are not a big fan of the way the Store holds on to modified records across remove/load actions. But that is how it has always worked and there is code that depends on that behavior, so changing it is not likely to happen. Repeatedly reporting bugs is not going to change how it works.

tbarstow
07-23-2007, 10:07 AM
thanks, Jack. That fixes it.

I agree about repeatedly reporting bugs and not breaking backwards compatibility. I honestly thought that the feature I had requested was a design goal of yours, since it was in the API docs.

Besides, javascript is a dynamic enough language that I can modify Store's functionality in my own javascript source if I really want to.

Thanks again!!

jack.slocum
07-23-2007, 04:45 PM
Hi tbarstow,

I wanted to let you know that for the next release, we added a config option "pruneModifiedRecords" that when true, will trigger the store to clear modified records on load and/or removal.

Hope that helps. :)

tbarstow
07-23-2007, 05:25 PM
:D thanks jack, you rock