PDA

View Full Version : [CLOSED] How do you dynamically create and populate a copy of a store in code-behind ?



betamax
Mar 07, 2014, 3:28 PM
Consider the simple store "stoUser" below that is loaded with data.



<ext:Store ID="stoUser" runat="server" >
<Model>
<ext:Model ID="modUser" runat="server">
<Fields>
<ext:ModelField Name="FirstName" />
<ext:ModelField Name="LastName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>


I need to dynamically create a copy of this store in code-behind and copy the data. This is something we were able to in Ext.Net v1. Below is the code I am trying to get to work;



var stoCopy = new Ext.Net.Store();
stoCopy.ID = "stoCopy";
stoCopy.ClientIDMode = ClientIDMode.Static;

var modCopy = new Ext.Net.Model();
modCopy.ID = "modCopy";
modCopy.ClientIDMode = ClientIDMode.Static;
foreach (ModelField fld in stoUser.Model[0].Fields)
{
modCopy.Fields.Add(fld);
}

stoCopy.Model.Add(modCopy);

stoCopy.Listeners.BeforeLoad.Handler += "App.stoCopy.data = App.stoUser.data.clone();";

Controls.Add(stoCopy);

Daniil
Mar 07, 2014, 5:23 PM
Hi @betamax,

Your code appears to be working to clone an instance of Store and I would load the data in a bit different way.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var stoCopy = new Ext.Net.Store();
stoCopy.ID = "stoCopy";
var modCopy = new Ext.Net.Model();
modCopy.ID = "modCopy";
modCopy.Fields.AddRange(stoUser.Model[0].Fields);
stoCopy.Model.Add(modCopy);

this.Form.Controls.Add(stoCopy);
}
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Store ID="stoUser" runat="server" >
<Model>
<ext:Model ID="modUser" runat="server">
<Fields>
<ext:ModelField Name="FirstName" />
<ext:ModelField Name="LastName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</form>
</body>
</html>

betamax
Mar 07, 2014, 8:23 PM
Turns out the original example I supplied works, we just had to add a delay to the call to clone.



stoCopy.Listeners.BeforeLoad.Handler += "App.stoCopy.data = App.stoUser.data.clone().delay(10);";

Solution found by user MDB
Thanks, mark as closed