PDA

View Full Version : [CLOSED] Add records with ModelProxy



osef
Jan 08, 2014, 7:55 AM
Hi, I want to add many records in a Store, but I have many columns, so, I want to use the object ModelProxy, because I use



sStore1.Add(new { Col1 = "Col11", Col2 = "Col12" ... Coln = "Col1n" });


So, It's a long line...

But, I don't know how to implent this object (ModelProxy), I am beging the example, but the contructor to ModelProxy It has a parameter AbstractStore, Could you please give me an example to ModelProxy in serverside?



<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:ComboBox
ID="cmbSucursal"
runat="server"
DisplayField="Nombre"
ValueField="Sucursal">
<Store>
<ext:Store ID="sSucursal" runat="server">
<DirectEvents>
<Load OnEvent="sSucursal_Load" />
</DirectEvents>
<Model>
<ext:Model ID="mSucursal" runat="server">
<Fields>
<ext:ModelField Name="Sucursal" Type="Int" />
<ext:ModelField Name="Nombre" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>




protected void sSucursal_Load(object sender, DirectEventArgs e)
{
for (int i = 0; i < 5; i++)
sSucursal.Add(new { Sucursal = i, Nombre = "Nombre" + i });

//Add with ModelProxy other five records
//ModelProxy mp = new ModelProxy(
}


7454

Daniil
Jan 08, 2014, 10:43 AM
Hi @osef,

Let's start from the fact that you are trying to add the records in a Store's Load DirectEvent. It looks very weird.

What about using a Store's DataSource?

As for a ModelProxy. It is not supposed to be used in the way that you are trying to use it.



sStore1.Add(new { Col1 = "Col11", Col2 = "Col12" ... Coln = "Col1n" });

So, It's a long line...


Could you, please, clarify why it is a problem? And I am not sure how you want to use a ModelProxy to avoid it.

osef
Jan 08, 2014, 4:28 PM
Hi @osef,

Let's start from the fact that you are trying to add the records in a Store's Load DirectEvent. It looks very weird.

What about using a Store's DataSource?

As for a ModelProxy. It is not supposed to be used in the way that you are trying to use it.



Could you, please, clarify why it is a problem? And I am not sure how you want to use a ModelProxy to avoid it.

Hi Daniil, It's just an example to add records in a Store's Load DirectEvent, Actually I want to add records from Click DirectEvent (Button), The user has a GridPanel where to add records one by one.

It is ModelProxy a parameter to add records in "Store1.add(ModelProxy mp)" so, there are 3 ways:

745574567457

So, I want to learn other way to add records in a Store from ServerSide.

Daniil
Jan 09, 2014, 10:56 AM
Here is an example.

To get the Add method with a ModelProxy working, please update from the SVN trunk (revision #5598).

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)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new
{
test1 = "test1",
test2 = "test2"
},
new
{
test1 = "test3",
test2 = "test4"
}
};
}
}

protected void Add1(object sender, DirectEventArgs e)
{
Store store = this.GridPanel1.GetStore();

store.Add(new
{
test1 = "new1",
test2 = "new2"
});
}

protected void Add2(object sender, DirectEventArgs e)
{
Store store = this.GridPanel1.GetStore();

store.Add(new object[]
{
new
{
test1 = "new3",
test2 = "new4"
},
new
{
test1 = "new5",
test2 = "new6"
}
});
}

protected void Add3(object sender, DirectEventArgs e)
{
Store store1 = this.GridPanel1.GetStore();
Store store2 = this.GridPanel2.GetStore();

ModelProxy rec = store1.GetAt(1);
store2.Add(rec);
}
</script>

<!DOCTYPE html>

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

<ext:Button runat="server" Text="Add a record to GridPanel1" OnDirectClick="Add1" />

<ext:Button runat="server" Text="Add several records to GridPanel1" OnDirectClick="Add2" />

<ext:Button runat="server" Text="Add the second record from GridPanel1 to GridPanel2" OnDirectClick="Add3" />

<ext:GridPanel ID="GridPanel1" runat="server" Title="GridPanel1">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test 1" DataIndex="test1" />
<ext:Column runat="server" Text="Test 2" DataIndex="test2" />
</Columns>
</ColumnModel>
</ext:GridPanel>

<br />

<ext:GridPanel ID="GridPanel2" runat="server" Title="GridPanel2">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test1" />
<ext:ModelField Name="test2" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test 1" DataIndex="test1" />
<ext:Column runat="server" Text="Test 2" DataIndex="test2" />
</Columns>
</ColumnModel>
</ext:GridPanel>
</form>
</body>
</html>