PDA

View Full Version : [CLOSED] Infinite Scrolling / onReadData / everything from code behind



tMp
Oct 01, 2013, 3:55 PM
Hi

I am trying to create an infinite scrolling gridpanel (http://examples2.ext.net/#/GridPanel/Infinite_Scrolling/Overview/)from code behind. Now I have some troubles with the OnReadData. It doesn't exist. What do I have to do? Tried some stuff with different proxies but nothing worked out so far....

In the end I would love to combine it with the a remote grid filter (http://examples2.ext.net/#/GridPanel/Plugins/GridFilters_Remote/). Is this even possible?


Thanks for any input.

best regards.

Daniil
Oct 01, 2013, 4:24 PM
Hi @tMp,


Now I have some troubles with the OnReadData. It doesn't exist.


I guess the Store doesn't exist, does it? Do you mean a server side exception when a PageProxy request occurs?

A PageProxy uses a Store's OnReadData event handler. The OnReadData event is a DirectEvent. As any DirectEvent it requires a control instance (a Store one in your case) on server when a request occurs. Since you create the Store dynamically, I guess you don't recreate it during each request.

There are two options.

1. Recreate the Store during each request.

or

2. Deny from a PageProxy and use an AjaxProxy referring to, for example, an HTTP handler (ashx).



In the end I would love to combine it with the a remote grid filter (http://examples2.ext.net/#/GridPanel/Plugins/GridFilters_Remote/). Is this even possible?


Yes, it should be possible.

tMp
Oct 01, 2013, 5:28 PM
@Daniil,

your are one step ahead of me ;)

My problem is:
OnReadData="Store_ReadData" in mark up. What is the equivalent in code behind because it doesn't exist when I try to create the store.

Daniil
Oct 01, 2013, 5:55 PM
Sorry, I misunderstood the question.

Here you are.

Store store = new Store();
store.ReadData += Store_ReadData;

It is for C#.

tMp
Oct 02, 2013, 9:13 AM
@Daniil

somehow I must be completely off....

Here is my demo code:

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

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

<!DOCTYPE html>

<script runat="server">

// on page load
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Window win = createTaskListWindow();

win.Render(this.form);
}
}

protected void store_ReadData(object sender, StoreReadDataEventArgs e)
{
//Store store = (Store)sender;
Store store = X.GetCmp<Store>("STORE_LIST");

Model model = new Model
{
Fields = {
new ModelField { Name = "ID", Type = ModelFieldType.Int },
new ModelField { Name = "NUMBER", Type = ModelFieldType.Int }
}
};
store.Model.Add(model);

int start = e.Start, limit = e.Start;

System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("NUMBER", typeof(int));

Random random = new Random();

for (int i = start + 1; i <= start + limit; i++)
{
dt.Rows.Add(i, random.Next(0, 10000));
}

store.DataSource = dt;
store.DataBind();
e.Total = 5000;
}

protected Window createTaskListWindow()
{
Store store = new Store
{
ID = "STORE_LIST",
Buffered = true,
PageSize = 200,
TrailingBufferZone = 10,
LeadingBufferZone = 10,
Proxy = { new PageProxy { } },
Model = {
new Model {
Fields = {
new ModelField { Name = "ID", Type = ModelFieldType.Int },
new ModelField { Name = "NUMBER", Type = ModelFieldType.Int }
}
}
}
};
store.ReadData += store_ReadData;

Window win = new Window
{
ID = "wList",
Title = "Demo",
Width = 812,
ManageHeight = true,
Items =
{
new GridPanel {
ID = "gpList",
Height = 800,
Store = { store },
ColumnModel = {
Columns = {
new Column { DataIndex = "ID", Text = "ID", Width = 50 },
new Column { DataIndex = "NUMBER", Text = "Random Number", Flex = 1 }
}
}
}
}
};

return win;
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>datefield demo</title>
</head>
<body>
<form id="form" runat="server">
<ext:ResourceManager ID="ResourceManager" runat="server" />
<div>

</div>
</form>
</body>
</html>

Is the PageProxy correct for DataTables and what reader do I need? If I run this I get an error like "The control with ID 'STORE_LIST' not found".

Daniil
Oct 02, 2013, 11:22 AM
Well, it is exactly I talked about here.



I guess the Store doesn't exist, does it? Do you mean a server side exception when a PageProxy request occurs?

A PageProxy uses a Store's OnReadData event handler. The OnReadData event is a DirectEvent. As any DirectEvent it requires a control instance (a Store one in your case) on server when a request occurs. Since you create the Store dynamically, I guess you don't recreate it during each request.

There are two options.

1. Recreate the Store during each request.

or

2. Deny from a PageProxy and use an AjaxProxy referring to, for example, an HTTP handler (ashx).


Also please use the Render method during DirectEvents/DirectMethods only.

win.Render(this.form);

During Page_Load please do this way:

this.form.Controls.Add(win);

tMp
Oct 02, 2013, 1:11 PM
Sorry, about the rendering-thing. That was a copy & paste error from my real scenario to the demo case.

For the recreation of the store, as I am going with version a. What I am doing wrong? As you told me in an earlier answer I am recreating the whole model of the store during each on "store_ReadData". I even tried it with reacreating the whole store but I still get the same error. Is is because the proxy has no reader? If so, what reader do I need for a DataTable? I am sorry, my brain seems to be caught in a loop.... :(

Thanks for your help.

Daniil
Oct 02, 2013, 4:18 PM
It is too late to recreate the Store within its OnReadData handler. The OnReadData handler requires a Store instance before its execution.

You can recreate the Store within the Page_Load.

tMp
Oct 03, 2013, 9:18 AM
@Daniil

Aaah, now I got the difference between the DirectEvent (always create it on page load) and the DirectMethod (only create it during call). Thanks!

In this case I will be avoiding DirectEvents for me because I don't see the sense in loading all this stuff on every page load just in case a user presses a button that to open a window that uses a DirectEvent. I will see if the buffered version suits my purpose better.

Daniil
Oct 03, 2013, 1:16 PM
Aaah, now I got the difference between the DirectEvent (always create it on page load) and the DirectMethod (only create it during call). Thanks!

Yes, a page's DirectMethod doesn't require a control instance on server.


In this case I will be avoiding DirectEvents for me because I don't see the sense in loading all this stuff on every page load just in case a user presses a button that to open a window that uses a DirectEvent.

Yes, it definitely makes sense.