Move next page in GridPanel when i reach the end of page when moving through down arrow key

  1. #1

    Move next page in GridPanel when i reach the end of page when moving through down arrow key

    Dear,

    I have a GridPanel and have implemented PageProxy in order to handle large datasets.

    Once the data is loaded in the grid i put the focus on the 1st row of the grid panel. This is because i want the user to move through rows without mouse.

    But when i reach the end of the page with pressing Down arrow key the Page does not change to next page and same thing with previous page if i reach an end while pressing Up arrow key.

    Can anyone tell me how do i change the page through javascript when user reaches the end or start of current page?

    Thanks,
    Huzefa
  2. #2
    Guys, any help would be appreciated.
  3. #3
    Hi,

    I can suggest the following solution.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <script runat="server">
        public List<object> MyData = new List<object> 
        { 
            new { test = "test1" },
            new { test = "test2" },
            new { test = "test3" },
            new { test = "test4" },
            new { test = "test5" },
            new { test = "test6" },
            new { test = "test7" },
            new { test = "test8" },
            new { test = "test9" }
        };
    
        protected void Store_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            List<object> data = this.MyData;
            var limit = e.Limit;
            if ((e.Start + e.Limit) > data.Count)
            {
                limit = data.Count - e.Start;
            }
            List<object> rangeData = (e.Start < 0 || limit < 0) ? data : data.GetRange(e.Start, limit);
            e.Total = data.Count;
            (sender as Store).DataSource = rangeData;
        }
    </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 myOnKeyPress = function (e, name) {
                var up = name == "up", 
                    method = up ? "selectPrevious" : "selectNext", 
                    add = up ? -1 : 1, 
                    last,
                    store = this.grid.getStore(),
                    pt = this.grid.getPagingToolbar(),
                    pageData,
                    ap,
                    ptMethod,
                    callback;
    
                if (this.last !== false && this.lastActive !== false) {
                    pageData = pt.getPageData();
                    ap = pageData.activePage;
    
                    if (up && !this.hasPrevious() && ap > 1) {
                        ptMethod = "movePrevious";
                        callback = function () {
                            this.selectLastRow();
                        };
                    } 
    
                    if (!up && !this.hasNext() && ap < pageData.pages) {
                        ptMethod = "moveNext";
                        callback = function () {
                            this.selectFirstRow();
                        };
                    }
    
                    if (ptMethod) {
                        pt[ptMethod]();
                        store.on("load", callback, this, { single : true });
                        return;
                    }
                }
                
                if (!e.shiftKey || this.singleSelect) {
                    this[method](false);
                } else if (this.last !== false && this.lastActive !== false) {
                    last = this.last;
                    this.selectRange(this.last, this.lastActive + add);
                    this.grid.getView().focusRow(this.lastActive);
                    if (last !== false) {
                        this.last = last;
                    }
                } else {
                    this.selectFirstRow();
                }
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store runat="server" OnRefreshData="Store_RefreshData">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="test" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <BaseParams>
                            <ext:Parameter Name="start" Value="0" Mode="Raw" />
                            <ext:Parameter Name="limit" Value="3" Mode="Raw" />
                        </BaseParams>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test" DataIndex="test" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server">
                        <CustomConfig>
                            <ext:ConfigItem Name="onKeyPress" Value="myOnKeyPress" Mode="Raw" />
                        </CustomConfig>
                    </ext:RowSelectionModel>
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar runat="server" PageSize="3" />
                </BottomBar>
            </ext:GridPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] Moving the <ext:XScript out of the Markup page ??
    By Fahd in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 19, 2012, 5:34 PM
  2. Replies: 1
    Last Post: Jan 25, 2012, 8:14 AM
  3. Replies: 2
    Last Post: May 05, 2010, 10:23 AM
  4. Move a window when the page is scrolled
    By fquintero in forum 1.x Help
    Replies: 0
    Last Post: Nov 23, 2009, 6:16 PM
  5. [CLOSED] Move Window in viewport to entire page
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 06, 2008, 6:48 AM

Tags for this Thread

Posting Permissions