[CLOSED] Auto Updating Store Custom Component

  1. #1

    [CLOSED] Auto Updating Store Custom Component

    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
    Last edited by Daniil; Oct 29, 2013 at 11:42 AM. Reason: [CLOSED]
  2. #2
    Hi Vincent,

    I am not sure what you mean under "auto update". Please elaborate in details.
  3. #3
    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.
  4. #4
    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.
  5. #5
    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>
    Last edited by Baidaly; Oct 22, 2013 at 11:50 PM.

Similar Threads

  1. Setting member variable of custom component
    By extneter in forum 2.x Help
    Replies: 3
    Last Post: Jun 20, 2013, 5:48 AM
  2. [CLOSED] Custom component ID creation difference with v 1.x
    By anup in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jul 30, 2012, 6:11 PM
  3. Replies: 0
    Last Post: May 03, 2011, 12:13 PM
  4. How to create custom client component class?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 24, 2008, 5:17 AM
  5. Replies: 3
    Last Post: Jul 29, 2008, 6:31 PM

Posting Permissions