PDA

View Full Version : How to edit a store using index values.



shashi7470
Feb 16, 2015, 9:55 AM
Hi.. i need edit a store using index values, without using any events (direct events or listeners)

simply passing its index value only and commitchanges to store.

RCN
Feb 25, 2015, 5:46 PM
On the following example, click on Add 5 Years (Index 1) button.

21871

21881


<!DOCTYPE html>
<html>
<head runat="server">
<script type="text/javascript">
var AddFiveYears = function (index) {
var recordFromStore = App._str.data.items[index];

recordFromStore.beginEdit();

recordFromStore.data.Age += 5;

recordFromStore.endEdit();

recordFromStore.commit();
}
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:GridPanel Title="Ext.NET" Border="true" Width="500" Height="400" runat="server">
<Store>
<ext:Store ID="_str" AutoLoad="true" runat="server">
<Proxy>
<ext:AjaxProxy Url="~/Example/LoadFakeRecords/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader RootProperty="data" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model IDProperty="ID" runat="server">
<Fields>
<ext:ModelField Name="ID" Type="String" />
<ext:ModelField Name="Name" Type="String" />
<ext:ModelField Name="Age" AllowNull="true" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Text="ID" DataIndex="ID" runat="server" />
<ext:Column Text="Name" Flex="1" DataIndex="Name" runat="server" />
<ext:Column Text="Age" DataIndex="Age" runat="server" />
</Columns>
</ColumnModel>
<Buttons>
<ext:Button Text="Add 5 Years (Index 1)" runat="server">
<Listeners>
<Click Handler="AddFiveYears(1);" />
</Listeners>
</ext:Button>
</Buttons>
</ext:GridPanel>
</body>
</html>




namespace SandBox.Controllers
{
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}

public StoreResult LoadFakeRecords()
{
List<Entity> lst = new List<Entity>();

for (int index = 1; index < 16; index++)
{
lst.Add(new Entity
{
ID = index,
Name = string.Format("Name - {0}", index),
Age = index
});
}

return new StoreResult(lst, lst.Count());
}
}

[Serializable]
public class Entity
{
public int ID { get; set; }

public string Name { get; set; }

public Nullable<int> Age { get; set; }
}
}

shashi7470
Feb 27, 2015, 9:08 AM
Thanks Bro for the reply..

RCN
Feb 27, 2015, 10:13 AM
Shashi7470, welcome to Ext.NET.