View Full Version : Copying Grids/Using Reconfigure

22 Jul 2010, 7:23 AM
So it's that time of the project where looking at the rat's nest that is my code I'm trying to clean it up and make it more modular and easier to read etc.

During the time of creation known as "just get it to work" we have 2 stores feeding 2 grids on 2 separate tabs. The problem with this is that 90% of the grid code is THE EXACT SAME with the changes coming in the form of references to the different store or a different variable that holds data specific to the different stores. The column model is the same and pretty much everything about it was just cut-and-pasted.

So I'm trying to clean this up and have run across the reconfigure function for gridpanels and want to know if that could be a suitable substitute for 45 LOC and then we could just make the individual changes to the new object like

gridfoo2 = gridfoo.reconfigure(newStore, colModel);
gridfoo2.makeChanges();Or would something like this change the nature of the original grid? Thoughts?

22 Jul 2010, 7:45 AM
So...I've found one stopping point from this and stop me if I'm wrong. We have different selModel configurations on the grids so even if the above solution could theoretically work we would be able to update the selModel configuration on the new object would we.

22 Jul 2010, 8:43 AM
I don't think the above solution would work, the reconfigure method returns void and acts on the grid you call it on. Anyway that wouldn't really be a good way to do this (unless I completely misunterstood what you're trying to do). You need to factor the common code for the grids in a single class that you will instantiate two times (or three or four etc when you add other panels)

There's a lot of tutorials on this in the "Application Design" section of the tutorial page. You need to look into the Ext.extend method (or using factory methods).

22 Jul 2010, 8:55 AM
Thanks. That's what I was thinking and was afraid of but figured I'd try hard to not have to do that.

22 Jul 2010, 9:05 AM
Fear not! Once you get the basics you'll be able to produce much cleaner code. And believe me I've been through this :)