Login Register

Grid and Datastore sorting out of sync

While using the new dojox.grid I came across this situation. While using a data store and the dojox.grid modifying the data in the store does not correspond to the grid correctly. I have listed some steps below to recreate this using the “dojox.Grid using Dojo.Data stores via simple binding” example.

http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test...

1. Click the Name header to sort the list alphabetically.
Note: The first four entries should now begin with A(Africa, Argentina, Asia, Australia)

2. Click the “Go!” button. This should change the type to “Thinger” for all entries that begin with an A. The code for this functionality is listed below:

function updateCountryTypes(){
// get everything starting with "A"
	jsonStore.fetch({
	query: { name: "A*" },
	onComplete: function(items, result){
			// change 'em!
			dojo.forEach(items, function(item){
				jsonStore.setValue(item, "type", "thinger");
				// console.debug(item);
			});
		}
	});
}

As you can see in the current view that the first and seventh entries changed, these originally contained the entries of Africa and Asia. Also the rows 1 – 3 did not change when they were suppose to.

I have noticed that, with

I have noticed that, with ItemFileReadStore:

1. The indexing of grid.model.store is in the order in which the data is retrieved from the source file/server and will stay in that order, regardless of sorting or changes to the Grid table rows.

2. The indexing of grid.model.data and the indexing of the Grid table row nodes are identical, change with sorting, and alway stay in sync with each other (but not with grid.model.store data).

3. Updating a value in the Grid table (via editor) or in grid.model.data, e.g., grid.model.setDatum(rowIndex, cellIndex) only updates the model (and Grid table) values. It does not change the grid.model.store values. This is expected, since this is a "Read" store.

In using ItemFileWriteStore (which the previous poster's example uses):

1. Once I complete a little more testing, I'll submit a ticket, with example code.

2. I've noticed that changing a Grid table value, e.g., clicking a dojox.editors.grid.Bool checkbox that is in a column that is mapped (via view) to an ItemFileWriteStore field/attribute, apparently randomly will update two rows, i.e., I click one checkbox and it, as well as another checkbox two rows above or below, will be set to checked.

3. I believe the above problem may be due to the Write store attempting to update the grid.model.data (which should reflect the Grid table values), and possibly the grid.model.store, using the grid.model.store index rather than the grid.model.data index. Those two indexes are out of sync after the first sort occurs.

I don't know if this is the cause of the problem reported above or not, but I will look further in the next few days.

in regards to (1)

I have seen this with the QueryReadStore as well, and have entered a ticket for it (http://trac.dojotoolkit.org/ticket/5261), I think it's a related problem.

-Jon

Thanks for looking into

Thanks for looking into this. Is there anything I can do to help? Also have you made a track ticket for it yet? If you have could, you attach it to the post so I can follow along.

Thanks again

Ticket #5275