DOJO Tutorial: Clear All Data From The Grid

Comments 3 Standard

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);
}
Advertisements

3 thoughts on “DOJO Tutorial: Clear All Data From The Grid

  1. does not work, does nothing, the rows are not eliminated, any idea what might be going on, thanks for your work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s