lang="en-US"> DOJO Tutorial: Clear All Data From The Grid –  Design1online.com, LLC

DOJO Tutorial: Clear All Data From The Grid

Unforutnately if you try to call the startup() function again (the logical way to create your grid all over again…come on now DOJO) you’ll get a the error: “Tried to register widget with id==grid but that id is already registered”.

For some reason DOJO wasn’t smart enough to clear out the old IDs associated with the grid. So the only way to clear all of the data out of the grid cells is to update the grid’s data store. Let’s say you have a grid called myGrid and you wanted a button to clear it. You could use the following function:

//this assumes myGrid is global
function clearMyGrid()
{
var emptyCells = { items: "" };
var emptyStore = new dojo.data.ItemFileWriteStore({data: emptyCells});
myGrid.setStore(emptyStore);
}

Now let’s say you wanted to make this function more generic so it will apply to any grid you want to clear. Update it to look like this instead:

//this allows you to clear any grid as long as you pass an instance of it to the function
function clearGrid(gridInstance)
{
    var emptyCells = { items: [] };
    var emptyStore = new dojo.data.ItemFileWriteStore({data: emptyCells});
    gridInstance.setStore(emptyStore);
}

You may also like...

Leave a Reply