How do we clear all the items from the Grid in ExtJS? - extjs

I am not looking at clearing all the store items with removeAll(). I have a paginated grid which has multiple pages. I want to clear out everything and before i assign new set of data , it should look afresh ? Does anyone know of any API ?
Regards

ExtJS grids are bound to an Ext.data.Store, all of their data comes from the store. If you want to clear the contents of a grid you'd have to clear the contents of its store.
If your data can be loaded from the same store URL with different parameters then you could try just manually overriding them when you want to load fresh data...
grid.getStore().load({
params: {
newParam: value
}
});

The way to clear grid data(without doing a backend hit) is to clear the associated store data and refresh the grid view.
Lets say transactionsGrid is associated with a store, then we can clear data shown in grid as below:
clear data using : transactionsGrid.store.clearData();
then refresh the grid view as : transactionsGrid.view.refresh();

Related

ExtJS Grid roweditor still dirty after grid save and store reload

I'm using ExtJS 5.1.3, I have a grid which is loaded from a store which has a model. The grid is set to use plugin roweditor, so I edit a cell and give it a new value, at this point the red tick is shown that the cell has been changed.
I have a Save button which when clicked gets the store.getModifiedRecords() and passes these off to a ajax request, upon success of this request a few things happen and the last action I do is to load the grid store again which then populates the grid again with the latest version of the data, this is fine and seems to be working as expected.
As this is a multi page application I also have a check when a user navigates away from this page, this is to catch any unsaved grid changes, so basically I get any form from the page and verify the isDirty() value, this is where I am finding my issue, the roweditor is being returned as dirty, this is because some columns have an editor and ExtJS uses form validation on these fields,
I can't understand why the store loading again has not cleared any dirty fields associated with the grid columns? I've tried a number of things such as clearing the store prior to ajax request along with refreshing the grid view, I've tried committing the store changes prior to doing the ajax request but each time I try navigate away from the page after a grid save I pick up the roweditor as having dirty fields :( any help is greatly appreciated.
EDIT: managed to replicate on a simple fiddle
https://fiddle.sencha.com/#view/editor&fiddle/1rmf
The fiddle is basic, to replicate follow these steps;
edit first row age, change age to 13
click Save (i'm forcing the store to load data which has the change we've made)
click 'Check roweditor is Dirty() value' button to see the value of the roweditor isDirty() function, this will return true
if you look at the button handler, you can drill into forms[0].items.items[2] and see that this field has dirty: true which is why isDirty() is returning true.
SOLUTION
As explained in accepted answer, the roweditor is not affected by the store edit/cancel or load in my case. What I did when clicking on 'Save' was to get the grid, then the editor and it's form and called reset() on this so effectively sync everything again.
grid.editingPlugin.getEditor().form.reset();
you can also get access to plugins via grid.getPlugins() which returns an arrary
updated fiddle to show it working
https://fiddle.sencha.com/#view/editor&fiddle/1rmr
During the editing process grid will eventually call loadRecord on the editor's form. However the editor's form is not cleared upon editing success or canceling. That is why your check for dirtyness returns false.
Grid reloading the data is not destroying the editors. It is an optimisation. Editors are created only once and they are destroyed along with the grid.
I'll try to answer regarding to an experience of mine with an all ExtJS desktop application.
By the way looking quickly over your description, you may have to call the Store.sync() method that refreshes your store.
Looking more deeply, there are many way to make CRUD using ExtJs.
I've been made using the "instance" of store but at certain point I had to change it to static calls like MyApp.store.Model.save() etc. That makes you have only one instance of the store avoiding dirty data.
Here's my project folder if you need
https://github.com/guilhermeribeirodev/grizzlyboilerplate/tree/master/src/main/webapp/js/MyApp

Extjs grid relies on external store, not rendering properly

I have an Extjs (version 6, classic API) panel with a grid in it. This grid has its own store that is ready to go within initComponent(). It's iterating over those records just fine. The issue is that one column has a custom renderer that relies on another store. This store may or may not be loaded depending on a few different factors. As a result, the grid doesn't render that column correctly. I find myself in a bit of a pickle as to how to deal with that. The basic concept is that the value for that column is just a key that means nothing to the user. This key is looked up in the non-grid store to display the data correctly using the renderer attribute in the grid column. All of the code is executing fine, but it's the issue of having that store loaded, and when it does load, it does not trigger a rerender of that column as it's not the store for the grid itself.
I could load the store synchronously before initComponent() is complete, but that's hardly ideal. I can't tell it to wait for the store to load during the render phase as that will leave the column blank if the store isn't loaded. I need to trigger a rerender of that column somehow or get it to properly wait if the non-grid store isn't loaded. Any ideas?
AFAIK there is no way to tell a grid to rerender a certain column. So you will have to refresh the whole grid:
myGrid.on('afterrender',function(grid) {
externalStore.on('load',function() {
grid.getView().refresh();
});
});

extjs 3 store load new records while keeping previous

I'm using a store to load data into a dataview tpl. The desired behavior is when user scrolls down to bottom, new records are loaded while previous remain there.
I've Already Tried This:
How to load additional records into the store/keep previous while loading new ones
But the above mentioned solution is not working for me as i'm trying to use it in ExtJS 3.
Is there any solution for ExtJS 3.4?
NB: I'm loading store every time user scrolls down to bottom by store.load();
check store.load method's add param,
which is Indicator to append loaded records rather than replace the current cache.
e.g.store.load({add:true})
refer docs

extjs-store-load

I have simple grid with a store. When I add a record to a store it reflects on the grid. But on few occasions when toggle between browser tabs.
The store load event seem to fire from then on when I add a record to the store its getting added but it don't seem to reflect on the grid
How do I stop the extjs store load event from firing on its own?
Have you thought about adding the following config option to your store?
autoLoad: false

How to dynamically change pagination urls in ExtJS?

I have two data grids. The first auto-loads a list of items (json data store). OnCellClick the first grid fires a dynamically parametrized url and loads data into the second grid. It works fine, but the pagination of the second grid does not focus the new context.
What shall I do to make the pagination work with the new url?
hm your pagination and second grid (which is the one to be dynamical) should share the same store, now on cell click you should only reconfigure the store and start loading it.
if you do like this both grid and pagination will work just fine...
i think currently your paginations uses another sotre (another instance or something) but it MUST use the same store as the second grid...
Not sure what you exactly mean with "does not focus the new context", but are you passing the start and limit parameters to the second grid in the params array of the jsonStore.load call?
If you just want to focus the grid on certain row, you can use focusRow method of GridView.
Perhaps you could post a code example if this did not help?

Resources