FetchItemByIdentity () is not working properly

I have an ItemFileWriteStore on my page. When I click on any row in my DataGrid , I can get the identifier of this row, but then when I try to make fetchItemByIdentity with this id, it always returns null . Any idea why this could be?

I am using Dojo 1.5.

 function getRemoveFormatter(id) { return '<a href="#" onclick="deleteItem(' + id + ');return false;"><img src="/images/icons/delete.png" /></a>'; } function deleteItem(id) { console.log(id); window.grid.store.fetchItemByIdentity({ identity: id, onItem: function(item, request) { console.log(item); } }); //window.grid.store.deleteItem(id); } dojo.ready(function() { var store = new dojo.data.ItemFileWriteStore({data:{items:[]}}); window.grid = new dojox.grid.DataGrid({ store: store, structure: [ { name: "id", field: "id", width: "50px" }, { name: "Stylist", field: "stylist", width: "100px" }, { name: "Service", field: "service", width: "200px" }, { name: "Length", field: "length", width: "50px" }, { name: "Remove", field: "remove", width: "30px", formatter: getRemoveFormatter } ], identifier: "id", label: "id"}); dojo.byId("services_grid").appendChild(grid.domNode); grid.startup(); observeAppointmentServiceAddClick(window.grid); getAppointmentItems(); }); 
+4
source share
2 answers

Try making a small change to the way the store and grid are advertised. Identifier and label properties belong in the store data section next to the items.

 var store = new dojo.data.ItemFileWriteStore({data:{ items:[], identifier: "id", label: "id"}}); window.grid = new dojox.grid.DataGrid({ store: store, structure: [ { name: "id", field: "id", width: "50px" }, { name: "Stylist", field: "stylist", width: "100px" }, { name: "Service", field: "service", width: "200px" }, { name: "Length", field: "length", width: "50px" }, { name: "Remove", field: "remove", width: "30px", formatter: getRemoveFormatter } ]}); 
+2
source

Here is a simpler code and answer for jsfiddle.

http://jsfiddle.net/martlark/UkKXW/1/

 <html> <head><!--dojo stuff--></head> <body> <div id='store'></div> <div id='log'></div> </body> </html> dojo.require("dojo.data.ItemFileWriteStore"); var store = null; function getItem(id) { store.fetchItemByIdentity({ identity: id, onItem: function (item, request) { var v = store.getValue(item, 'value'); dojo.byId('log').innerHTML = 'getItem(' + id + ') =' + v; } }); } dojo.ready(function () { var items = []; for (var p = 0; p < 5; p++) { items.push({ id: p, value: 'v ' + p }); } store = new dojo.data.ItemFileWriteStore({ data: { identifier: 'id', items: items } }); var gotList = function (items, request) { var itemsList = "<ul>"; dojo.forEach(items, function (i) { itemsList += '<li> id:' + p + ' = ' + store.getValue(i, "value") + "</li>"; }); itemsList += '</ul>'; dojo.byId('store').innerHTML = itemsList; } var gotError = function (error, request) { alert("The request to the store failed. " + error); } // Invoke the search store.fetch({ onComplete: gotList, onError: gotError }); getItem('2'); }); 
+1
source

All Articles