PDA

View Full Version : [CLOSED] Issue when adding data to the store



RCN
Apr 17, 2012, 5:47 PM
Hi Folks, when i click button4 a javascript function is called to add (append) a record to the store but a javascript exception is raised (Microsoft JScript runtime error: 'Me' is undefined) as shown in the following image:

4119

ive also tried to use store.add, store.insert (making the appropriate changes) but i got the same result.

Any ideas to overcome this problem?

View


<ext:GridPanel ID="GridPanel1" runat="server" Title="GRD">
<Store>
<ext:Store ID="Store1" runat="server" PageSize="10" RemoteSort="true" AutoLoad="true">
<Proxy>
<ext:AjaxProxy Url="/Example/Test/">
<Reader>
<ext:JsonReader Root="data" TotalProperty="total" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="ID" />
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
<Listeners>
</Listeners>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
<ext:Column ID="Column3" runat="server" Text="Name" DataIndex="Name" />
</Columns>
</ColumnModel>
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button ID="button4" runat="server" Text="Add Record">
<Listeners>
<Click Handler="addRecord();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>


JavaScript



<script type="text/javascript">
var addRecord = function () {
Ext.net.DirectMethod.request({
url: "/Example/LoadRecord",
cleanRequest: true,
success: function (result) {
App.Store1.loadData(result, true);
App.Store1.commitChanges();
}
});
}
</script>


Controller Methods


public StoreResult Test(int start, int limit)
{
StoreResult response = new StoreResult();


List<Person> data = new List<Person>();


Random randow = new Random();
DateTime now = DateTime.Now;


for (int i = start + 1; i <= start + limit; i++)
{
Person qoute = new Person()
{
ID = i,
Name = "name " + i,
};

data.Add(qoute);
}


response.Data = data;
response.Total = 50000;

return response;
}

public StoreResult LoadRecord()
{
StoreResult response = new StoreResult();

response.Data = new List<Person> { new Person { ID = 999, Name = "EXT" } };

response.Total = 1;

return response;
}


Entity


public class Person
{
public int ID { get; set; }

public string Name { get; set; }

}

Daniil
Apr 17, 2012, 6:09 PM
Hi,

There are two issues.

1. You should use

result.data
instead of just "result".

App.Store1.loadData(result.data, true);

2. There is a bug within the commitChanges function. We will fix soon. Thanks for the report.

Daniil
Apr 17, 2012, 6:12 PM
For now, you can just remove the commitChanges call. I don't think it's required after the loadData.

RCN
Apr 17, 2012, 7:17 PM
Thumbs up to you. Please mark it as solved