[CLOSED] GridPanel select and scroll to inserted row

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] GridPanel select and scroll to inserted row

    Hello,

    I have GridPanel with pagging with attached JSON store data.
    How can I select inserted (added) new row from "window"?

    I think I know how select row when I'm on grid first page,
    but I don't know how to scroll and select this record when I'm on other grid page?
    Last edited by Daniil; Sep 29, 2010 at 6:42 PM. Reason: [CLOSED]
  2. #2
    Hi smart+,

    Please look at the example.

    At the moment I'm investigating why the scroll comes back to the first row.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] { 
                                             new object[] {"test0" },
                                             new object[] {"test1" },
                                             new object[] {"test2" },
                                             new object[] {"test3" },
                                             new object[] {"test4" },
                                             new object[] {"test5" },
                                             new object[] {"test6" },
                                             new object[] {"test7" },
                                             new object[] {"test8" }
                                             
                                    };
                store.DataBind();
            }
        }
    </script>
    
    <!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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var addRowAndSelectAndScroll = function(grid, record) {
                grid.getStore().add(record);
    
                var pagingToolbar = grid.getBottomToolbar();
    
                pagingToolbar.indexToSelect = grid.getStore().getTotalCount() - 1,
    
                pagingToolbar.on('change', changeHandler); //to select row
                grid.getStore().on('datachanged', datachangedHandler); //to scroll
                grid.getView().rowHeight = grid.getView().getRow(0).offsetHeight;
                setPage(pagingToolbar);
            }
    
            var changeHandler = function() {
                GridPanel1.getSelectionModel().selectRow(this.indexToSelect % this.pageSize);
                this.un('change', changeHandler);
            }
    
            var setPage = function(pagingToolbar) {
                var newPage = Math.ceil((pagingToolbar.indexToSelect + 1) / pagingToolbar.pageSize);
                pagingToolbar.changePage(newPage);
            }
    
            var datachangedHandler = function() {
                var pagingToolbar = GridPanel1.getBottomToolbar(),
                    view = GridPanel1.getView();
                view.scroller.scroll('b', view.rowHeight * (pagingToolbar.indexToSelect % pagingToolbar.pageSize));
                this.un('datachanged', datachangedHandler);
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            Height="100" 
            Width="500">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test" DataIndex="test" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel runat="server" />
            </SelectionModel>
            <BottomBar>
                <ext:PagingToolbar runat="server" PageSize="5" />
            </BottomBar>
        </ext:GridPanel>
        <ext:Button runat="server" Text="Add row">
            <Listeners>
                <Click Handler="var newRecord = new Ext.data.Record();
                                newRecord.set('test', 'test new');
                                addRowAndSelectAndScroll(#{GridPanel1}, newRecord); " />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    I have the same problem.
    i expect an answer from the developers.
  4. #4
    Hi,

    Here is the refactored and worked code.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] { 
                                             new object[] {"test0" },
                                             new object[] {"test1" },
                                             new object[] {"test2" },
                                             new object[] {"test3" },
                                             new object[] {"test4" },
                                             new object[] {"test5" },
                                             new object[] {"test6" },
                                             new object[] {"test7" },
                                             new object[] {"test8" }
                                             
                                    };
                store.DataBind();
            }
        }
    </script>
    
    <!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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var addRowAndSelectAndScroll = function(grid, record) {
                grid.getStore().add(record);
    
                var pagingToolbar = grid.getBottomToolbar(),
                    indexToSelect = grid.getStore().getTotalCount() - 1;
    
                pagingToolbar.on('change', changeHandler,
                    { //scope object
                        scope: pagingToolbar,
                        indexToSelect: indexToSelect,
                        grid: grid
                    },
                    { //options
                        delay: 10, //Possibly it needs to increase this for more rows
                        single: true
                    }
                );
    
                setPage(pagingToolbar, indexToSelect);
            }
    
            var changeHandler = function() {
                this.grid.getSelectionModel().selectRow(this.indexToSelect % this.scope.pageSize);
                this.grid.getView().focusRow(this.indexToSelect % this.scope.pageSize);
            }
    
            var setPage = function(pagingToolbar, indexToSelect) {
                var newPage = Math.ceil((indexToSelect + 1) / pagingToolbar.pageSize);
                pagingToolbar.changePage(newPage);
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server" 
            Height="100" 
            Width="500">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="test" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test" DataIndex="test" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel runat="server" />
            </SelectionModel>
            <BottomBar>
                <ext:PagingToolbar runat="server" PageSize="5" />
            </BottomBar>
        </ext:GridPanel>
        <ext:Button runat="server" Text="Add row">
            <Listeners>
                <Click Handler="var newRecord = new Ext.data.Record();
                                newRecord.set('test', 'test new');
                                addRowAndSelectAndScroll(#{GridPanel1}, newRecord); " />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
    Last edited by Daniil; Sep 28, 2010 at 9:49 PM.
  5. #5
    Store store = this.GridPanel1.GetStore();
    
    Error    2014    'Ext.Net.GridPanel' does not contain a definition for 'GetStore' and no extension method 'GetStore' accepting a first argument of type 'Ext.Net.GridPanel' 
    could be found (are you missing a using directive or an assembly reference?)

    The record is added via javascript ExtJS.
    newRecord.set
    You can not get the same results working on the server side?
    doing the databind?
    Last edited by Daniil; Sep 29, 2010 at 8:10 AM. Reason: Please use [code] tags
  6. #6
    Hi,

    I think updating from the SVN would solve GetStore() method issue. It's appeared in the toolkit not too long time ago.
    Or you could use this instead of GetStore():

    Example
    GridPanel1.Store.Primary
    Yes, you're right. One way is doing DataBind().

    The second way just adding a script like this:

    Example
    this.GridPanel1.AddScript("GridPanel1.getStore().add(new Ext.data.Record({test: 'new test'}))");
  7. #7
    I do not use subversion.
    how do I get the updated version?
  8. #8
    Hi,

    You could use a SVN manager like this
    http://tortoisesvn.tigris.org/

    Here is the url with Ext.Net 1.0
    http://svn.ext.net/premium/branches/1.0.0/

    The login and password should be sent on your e-mail when you purchased the license.
  9. #9
    Unfortunately in my office pc can not install new programs.
    I can download the new version via ftp?
  10. #10
    I'm not sure it's possible...

    I'm afraid that there is only one way to get it - downloading each file step by step. But repeat myself I'm not sure.

    Maybe I can send you the latest dll on your e-mail?
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: May 24, 2012, 7:39 AM
  2. [CLOSED] gridpanel scroll bar
    By lonely7345 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 11, 2011, 4:48 PM
  3. [CLOSED] I can not edit inserted record in a grid.
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 03, 2010, 8:20 PM
  4. [CLOSED] GridView select only edited or inserted rows
    By GmServizi in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 06, 2009, 4:46 AM
  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