PDA

View Full Version : [CLOSED] Cloning components and stores



craig2005
Jun 06, 2012, 1:43 AM
Is there any way to clone a component or store?

I found something on the web like Ext.net.clone but it didn't exist for me.

Daniil
Jun 06, 2012, 7:58 AM
Hi,

Ext.net.clone is for cloning simple variables including array, {}-like objects without keeping the old reference.

There is an ExtJS analog with extended functionality to also clone DOM nodes and Date.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-clone

I will consider with my colleagues we do still need our own Ext.net.clone method or not.

Regarding your issue with cloning components. Please use the cloneConfig method to clone Ext.Components.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Component-method-cloneConfig

Store is not an inheritor of Ext.Component, so, there is no cloneConfig method.

But I am not sure you need two same Stores. You could attach a single Store to any amount of bindable components.

Please clarify why do you need to clone it?

Vladimir
Jun 06, 2012, 10:33 AM
Please avoid cloning of components, UI control is complex object and cannot be clonned correctly in all cases.
It much better to create method which creates required widget. If you know that a type of widget can be used in several places then create method to create and return the widget. It is more safely.

Another option, implement custom control, after that you will be able to create widgets of the same type

craig2005
Jun 06, 2012, 3:59 PM
But I am not sure you need two same Stores. You could attach a single Store to any amount of bindable components.

Please clarify why do you need to clone it?

I wanted to create multiple instances of a store as I'm not sure how to share the same store across multiple data grids and then filter each grid to show a different part of the store's data.

craig2005
Jun 06, 2012, 4:19 PM
I basically want 4 identical grids sharing the same store but with different filters.

I was hoping I could use the <ext:GridPanel> tag to create a grid wrapped in a container. Then when loading the page (Page_Load function), I could copy the grid and dynamically created 3 other grids with the same store but with different filters and add them to the container. It seemed trivial at first, but I ended up hitting a bunch of road blocks.

Daniil
Jun 06, 2012, 6:41 PM
Yes, if you need different filtering, you need different stores.


I was hoping I could use the <ext:GridPanel> tag to create a grid wrapped in a container. Then when loading the page (Page_Load function), I could copy the grid and dynamically created 3 other grids with the same store but with different filters and add them to the container. It seemed trivial at first, but I ended up hitting a bunch of road blocks.

The following thread could, probably, help to copy/clone a control.
http://forums.asp.net/t/617980.aspx

Though I would also prefer, as Vladimir suggested, to create a code behind method which would create and return a GridPanel (with Store) instance. Then you could easily create as many same GridPanel instances (just changing IDs) as you wish.

Implementing a custom server control inherited from GridPanel would be even better in the design aspect.

craig2005
Jun 07, 2012, 5:24 PM
Yeah, I've changed my approach to write code to create the grid panel from scratch in c#.

What's the solution for cloning the data from a store? Could I add a custom row filter and filter the grid's rows and not the actual store?

Daniil
Jun 07, 2012, 7:16 PM
What's the solution for cloning the data from a store?

Well, you should set up the same object to Stores DataSource.


Could I add a custom row filter and filter the grid's rows and not the actual store?

No, filtering (and any other data layer operations like loading, sorting, grouping) is performed on Store level.

craig2005
Jun 08, 2012, 2:59 AM
Can I bind multiple stores to a single datasource? Would that be the way to go?

craig2005
Jun 08, 2012, 3:33 AM
Am i missing something?


store.Listeners.Load.Fn = "populateSolrStores('" + id + "')";

When you use a Handler the code works fine. When you use Fn, it immediately tries to execute the code in the function. This was driving me nuts and I thought the load event was broken until i tried calling this function through the "Handler" method instead.

geoffrey.mcgill
Jun 08, 2012, 4:36 AM
Hi,

The .Fn property is looking for a 'function' object. Either pass the name of the function, or function () {}.

You are calling a function, which should be set on the .Handler property. The .Handler wraps your code in a function () {} template, which will be executed when the event/listener is fired.

Hope this helps.

Daniil
Jun 08, 2012, 8:30 AM
Can I bind multiple stores to a single datasource? Would that be the way to go?

Well, I can't see a problem here.

Store1.DataSource = data;
Store1.DataBind();
Store2.DataSource = data;
Store2.DataBind();

If you mean ASP.NET DataSource controls like SqlDataSource or LinqDataSource, then, I think, you can refer as many Stores as you wish to a single DataSource control setting up the Stores DataSourceID property.