grid.startup() not working for different data in the Dojo data grid
Below I have pasted a function to show the data in the datagrid based on the function call shownames('a'). DataGrid is not refreshing for different characters like shownames('b')...and so on . Or, How do I change the data in the datagrid without destroying the grid completely ?
function shownames(chr) { require([ "dojox/grid/EnhancedGrid", "dojo/store/Memory", "dojo/data/ObjectStore", "dojo/_base/xhr", "dojo/domReady!" ], function(DataGrid, Memory, ObjectStore, xhr){ var grid, dataStore; xhr.get({ url: "http://localhost/xampp/namedb.php?name_idx="+chr, handleAs: "json" }).then(function(data){ dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) }); if(dijit.byId("namegrid")) { grid.destroy(); } else { grid = new dojox.grid.EnhancedGrid({ id: "namegrid", store: dataStore, query: { name_id: "*" }, queryOptions: {}, structure: [ { name: "Name", field: "name", width: "25%" }, { name: "Actual Meaning", field: "meaning", width: "50%" }, { name: "name_id", field : "name_id", hidden: true } ] }, "alphanames"); grid.startup(); } /* dojo.connect(grid, "onRowClick", grid, function(evt){ var idx = evt.rowIndex, item = this.getItem(idx); // get the ID attr of the selected row var value = this.store.getValue(item, "country_name"); }); */ }); }); }
Thanks, Raja
you should not refresh the grid the way you posted it !
First you need to initialize a grid at startup. So the grid shows you some data. Dont create a grid each time !!!! AFTER that your function has to communicate with the grid by using it's methods !
I constantly use this bulk to refresh the grid:
var grid= // CREATE GRID IN HERE
function yourFunction(id) {
var prepareQuery={};
prepareQuery["name_id"]=id; // Create a query based on id
grid._pending_requests={}; // Stop everything thats loading
grid._setQuery(prepareQuery); // Pass query to the grid
grid._refresh(true); // Refresh grid
}
It may also work with your code, but you may have to do some adaptions.
链接地址: http://www.djcxy.com/p/60458.html