PDA

View Full Version : [CLOSED] Auto Updating Store Custom Component



vgvallee
Oct 22, 2013, 7:54 PM
I am trying to extend a store in a custom component. It should auto update. In the example below, the DataSource is an XML file that is refreshed by another process.



public class ExtendedStore: Ext.Net.Store
{
protected override void OnInit(EventArgs e)
{
this.AutoLoad = true;
this.Model.Add(new Ext.Net.Model
{
IDProperty = "field1",
Fields = {
new Ext.Net.ModelField("field1", Ext.Net.ModelFieldType.Int)
}
});
this.DataSource = new System.Web.UI.WebControls.XmlDataSource()
{
DataFile = "~/data.xml"
};

base.OnInit(e);
}
}



How would I go about doing that?

Thanks,
Vincent

Daniil
Oct 22, 2013, 8:45 PM
Hi Vincent,

I am not sure what you mean under "auto update". Please elaborate in details.

vgvallee
Oct 22, 2013, 8:49 PM
I want to reload the store at fixed intervals because the server data is updated. I have done it in markup but I haven't been able to do it in a C# class to extend a control.

vgvallee
Oct 22, 2013, 8:53 PM
I have tried to put an instance of a Task in a TaskManager and call StartTask in OnLoad:



private Ext.Net.TaskManager taskManager = new Ext.Net.TaskManager();
private Ext.Net.Task task = new Ext.Net.Task(new Ext.Net.Task.Config() { Interval = 5 * 1000, TaskID = "AutoUpdateTask", AutoRun = true, Listeners = { Update = { Handler="function(){ console.log('update'); }" } } });


In OnInit:


taskManager.AddTask(task);
this.Controls.Add(taskManager);


In OnLoad:


protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (!Ext.Net.X.IsAjaxRequest)
{
taskManager.StartTask("ObservedAutoUpdate");
}
}


but the Task does not serialize properly in the JavaScript generated. I only get Interval and TaskID. No AutoRun or Listeners present.

Baidaly
Oct 23, 2013, 12:44 AM
Hello!

You should pass parameter for the task directly without Config object. Look at the following sample, also there is another option using setTimeout in OnInit method:


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

<%@ Import Namespace="System.Threading" %>

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

<script runat="server">
public class ExtendedStore: Ext.Net.Store
{
private Ext.Net.TaskManager taskManager = new Ext.Net.TaskManager();
private Ext.Net.Task task = new Ext.Net.Task
{
Interval = 5 * 1000,
TaskID = "AutoUpdateTask",
AutoRun = true,
Listeners =
{
Update = { Handler = "function(){ console.log('update'); }" }
}
};

protected override void OnInit(EventArgs e)
{
this.AutoLoad = true;
this.Model.Add(new Ext.Net.Model
{
IDProperty = "field1",
Fields = {
new Ext.Net.ModelField("field1", Ext.Net.ModelFieldType.Int)
}
});
this.DataSource = new System.Web.UI.WebControls.XmlDataSource()
{
DataFile = "~/data.xml"
};

// *** Another option
// this.Listeners.Load.Handler = @"setInterval(function(){
// console.log('update');
// }, 5000);";
// this.Listeners.Load.Single = true;

taskManager.Tasks.Add(task);
this.Controls.Add(taskManager);

base.OnInit(e);
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (!Ext.Net.X.IsAjaxRequest)
{
//taskManager.StartTask("ObservedAutoUpdate");
}
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Panel1.Items.Add(new GridPanel()
{
Store = { new ExtendedStore() }
});
}
}


</script>
<!DOCTYPE html>

<html>
<head runat="server">
</head>
<body>
<form runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Panel runat="server" ID="Panel1"></ext:Panel>
</form>
</body>
</html>