[CLOSED] TreeGrid scroll position after refresh

  1. #1

    [CLOSED] TreeGrid scroll position after refresh

    I have a treegrid that is filled every 5 seconds by this way:

    Ext.net.DirectMethods.RefreshLogTree({
        eventMask: {
            showMask: false
        },
        success: function (result) {
            if (result != "") {
                var nodes = Ext.util.JSON.decode(result);
                tree.root.ui.remove();
                tree.initChildren(nodes);
                tree.root.render();
            }
        }
    });
    It works fine, nodes are loaded correctly. The problem is when there are lot of nodes and vertical scroll is enabled and you are inthe middle of the scroll next time the grid refreshes loose the scroll and it goes to the top of the grid.

    Is there any way to maintain the scroll position or to force the scroll to go to the end / last row?
    Last edited by Daniil; Mar 19, 2013 at 4:23 AM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @agonzalez,

    I think saving a scroll's position before re-rendering and restoring after re-rendering could be a solution.

    You use Ext.NET v1, don't?
  3. #3
    Yes, I am using ext.net v1.3

    Can you post an example how to save and restore treegrid position and how to scroll to the end?. Thanks.
  4. #4
    Please post Ext.NET v1 related question on the Premium Help 1.x forum. Moved to this forum.

    Please provide a sample to test with.
  5. #5
    
    <%@ Page Language="C#" %>
        <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
                
                <head id="Head1" runat="server">
                    <title></title>
                    <script language="javascript" type="text/javascript">
                        var Timer = {
                            maxFailures: 3,
                            failure: 0,
                            inertval: null,
                            taskInProgress: false,
                            stoped: true,
                            startTask: function () {
                                this.inertval = setInterval(function () {
                                    refreshLogTree(treeJobLog);
                                }, 5000);
                                this.stoped = false;
                            },
                            stopTask: function () {
                                clearInterval(this.inertval);
                                this.inertval = null;
                                this.stoped = true;
                            }
                        };
    
                        function refreshLogTree(tree) {
                            if (!Timer.taskInProgress) {
    
                                Timer.taskInProgress = true;
                                Ext.net.DirectMethods.RefreshLogTree({
                                    eventMask: {
                                        showMask: false
                                    },
                                    success: function (result) {
                                        if (!Timer.stoped) {
                                            Timer.taskInProgress = false;
                                            if (result != "") {
                                                var nodes = Ext.util.JSON.decode(result);
                                                tree.root.ui.remove();
                                                tree.initChildren(nodes);
                                                tree.root.render();
                                            }
                                        }
                                    },
                                    failure: function (msgData) {
                                        Timer.taskInProgress = false;
                                    }
                                });
    
    
                            }
                        };
                    </script>
                    <script runat="server">
                        public class JobStep {
                            public string Step {
                                get;
                                set;
                            }
                            public string Result {
                                get;
                                set;
                            }
                        }
    
                        [DirectMethod]
                         public string RefreshLogTree() {
                            return BuildLogTree().ToJson();
                        }
    
                        private Ext.Net.TreeNodeCollection BuildLogTree() {
                            var root = new Ext.Net.TreeNode {
                                NodeID = "Job Root", Text = "Job Root"
                            };
                            for (var i = 0; i <= 200; i++)
                            root.Nodes.Add(NewNode(i));
    
                            var nodes = new Ext.Net.TreeNodeCollection();
                            nodes.Add(root);
                            return nodes;
                        }
    
                        private Ext.Net.TreeNode NewNode(int number) {
                            var treeNode = new Ext.Net.TreeNode {
                                Icon = Ext.Net.Icon.Star,
                                NodeID = string.Format("node{0}", number),
                                Leaf = true,
                                Expandable = ThreeStateBool.False
                            };
                            treeNode.CustomAttributes.Add(new ConfigItem("Step", string.Format("step {0}", number), ParameterMode.Value));
                            treeNode.CustomAttributes.Add(new ConfigItem("Result", "ok", ParameterMode.Value));
                            return treeNode;
                        }
                    </script>
                </head>
                
                <body>
                    <form id="frmJobLog" runat="server">
                        <ext:ResourceManager ShowWarningOnAjaxFailure="false" ID="rm" runat="server">
                            <Listeners>
                                <DocumentReady Handler="Timer.startTask();" />
                            </Listeners>
                        </ext:ResourceManager>
                        <ext:Viewport ID="Viewport1" runat="server">
                            <Items>
                                <ext:FitLayout ID="FitLayout1" runat="server">
                                    <Items>
                                        <ext:TreeGrid ID="treeJobLog" runat="server" EnableSort="false" Cls="plain-treegrid" EnableDD="False" Border="false" BodyBorder="false" AutoExpandColumn="Step" AutoScroll="True" AutoExpandMax="10000">
                                            <TopBar>
                                                <ext:Toolbar ID="Toolbar1" runat="server">
                                                    <Items>
                                                        <ext:Button ID="btnStop" runat="server" Text="Stop" IconCls="kill">
                                                            <Listeners>
                                                                <Click Handler="Timer.stopTask();" />
                                                            </Listeners>
                                                        </ext:Button>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                            <Columns>
                                                <ext:TreeGridColumn Header="Step" Width="230" DataIndex="Step" />
                                                <ext:TreeGridColumn Header="Result" Width="230" DataIndex="Result" />
                                            </Columns>
                                        </ext:TreeGrid>
                                    </Items>
                                </ext:FitLayout>
                            </Items>
                            <Listeners>
                                <Render Handler="this.getEl().on('contextmenu', Ext.emptyFn, null, {preventDefault: true});" />
                            </Listeners>
                        </ext:Viewport>
                    </form>
                </body>
            
            </html>
    Last edited by agonzalez; Mar 14, 2013 at 3:04 PM.
  6. #6
    Please see #3 here:
    More Information Required

    Also please read the following guide.
    Forum Guidelines For Posting New Topics
  7. #7
    Thank you.

    Reproduced with v1.3, but not with either the last public release v1.6 or the latest sources from SVN.

    So, please update.

Similar Threads

  1. Maintain scroll position in dataview
    By dotnet in forum 1.x Help
    Replies: 0
    Last Post: Jan 28, 2013, 10:10 AM
  2. Replies: 1
    Last Post: Oct 06, 2011, 8:12 AM
  3. [CLOSED] Grid - scroll position
    By jwf in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 26, 2011, 11:13 PM
  4. [CLOSED] Maintain scroll position in Ext.NET
    By skyone in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 27, 2010, 12:15 PM
  5. multi select scroll position
    By [WP]joju in forum 1.x Help
    Replies: 1
    Last Post: Apr 13, 2009, 12:13 PM

Posting Permissions