I am just making my baby steps around the Dojo world. I am amazed at all the things I did not know :-).
My question is what is the best way to fetch a row from using the row index from the Grid?
I have a custom store that extends ItemFileWrite store. This store has a method , saveItem with the following body.
<javascript>
saveItem:
function( index,
templateToSave,
postUrl,
postVariable,
_onLoad,
_onError) {
var item = this._arrayOfAllItems[index];
var itemToSave = this.constructSaveString(item);
var contentData = {};
var dataStringToSend = JSON.stringify(itemToSave); //Could have used dojo.toJson
contentData[postVariable]=dataStringToSend;
//alert("SENDING : " + dataStringToSend );
dojo.xhrPost({
url: postUrl,
handleAs: "json",
content: contentData,
load: _onLoad,
error: _onError
});
},
</javascript>
The bolded line returns null when queried using the supplied index. What is the right way to fetch the right item from the store using the index of the row from the grid?

Not sure if this is what you
Not sure if this is what you are looking for, as there are several ways to get the data you want.
From outside the store's source code (not what you are doing), you can get the data object associated with a specific grid row index by doing:
var dataItem = dijit.byId('grid').model.getRow(gridRowIndex); or by: var dataItem = dijit.byId('grid').model.data[gridRowIndex]; and get any of the field values that appear in the grid model by: var id = dataItem.id; //dataItem.fieldName If id is the key field (Identifier), and the field value you want is in your store but not in your model, you can get id as above, and then get the desired store field value by: var storeItemValue = dijit.byId('grid').model.store._getItemByIdentity(id).catnameseq[0];I didn't look at the source, but I would think the store's onSet method/extension point supplies you the item, attribute, oldvalue, newvalue, etc., from which you could get any/all data for an item that has been saved/changed in the store. And I would think the placeholder "save" or similar method/extension point in the store would also supply you, as passed parameters, the info you need. If you don't find it, reply here and I or someone will look closer. Good luck on your dojo journey... :)
Looking at your message again, I doubt the index being passed is the grid's row index but the specific index into the store.
It might work
Yes, The mothods you outlined would definitely work for me. All I need to do is to change saveItem: method to expect the 'item' rather than the row Index. Then from outside, I'd identify the item through the model and pass it into the function. Thank you!
Another Qn : Whats the best way to add a new row to a grid at the run time?. I tried using store.newItem. However the grid is not refreshing. Is there a better access mechanism through the model?, Is grid.render(); the right method to repaint a grid?
I would only use
I would only use grid.render() upon initial programmatic creation of a grid, then grid.update() thereafter, if needed. However, if you change the grid "structure" (layout), you will need a grid.refresh() after setStructure().
But, what should work for you after adding the item (if it shows as being in the store), is to do a grid.model.refresh(), which rebuilds the grid model and rows from the data store, based on the query.