[CLOSED] maintain selection in gridpanel

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] maintain selection in gridpanel

    Hi,

    Can anyone give me an example on how to maintain a row selection when redirecting from one page to another and then coming back.

    Example:
    User selects a row in a grid panel on Page 1 and then clicks a button to go to another page say Page 2, now user does something here on page 2 and clicks a button on it and redirects back to Page 1 with the data collected from Page 2 and now in the end user get to see Page 1 with the initially selected row from the grid panel.

    Note: all my controls are without
    runat = "server"
    tag

    Please help
    Thanks
    Last edited by Daniil; Dec 23, 2015 at 11:08 AM. Reason: [CLOSED]
  2. #2
    Hi @sharmav1,

    A GridPanel in the example below maintains selection across the pages.

    The key point of this functionality is a ModelField's IDProperty. I.e. each record must have a unique id.

    Example
    <%@ Page Language="C#" %>
    
    <%@ 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_ReadData(object sender, StoreReadDataEventArgs 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>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:GridPanel ID="GridPanel1" runat="server">
                <Store>
                    <ext:Store runat="server" OnReadData="Store_ReadData" PageSize="3">
                        <Model>
                            <ext:Model runat="server" IDProperty="test">
                                <Fields>
                                    <ext:ModelField Name="test" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:PageProxy>
                                <Reader>
                                    <ext:JsonReader />
                                </Reader>
                            </ext:PageProxy>
                        </Proxy>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test" DataIndex="test" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" Mode="Multi" />
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar runat="server" />
                </BottomBar>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    Hi @Daniil,

    Thanks for your help with the example. But, I said earlier that I am not using
    runat="server"
    tag in my gridpanel or on any other control.

    Also, I am working on mvc 4 with razor syntax, so if possible please give any example in that.

    Thanks
  4. #4
    This functionality doesn't require runat="server".

    Unfortunately, I don't have a Razor example at hand. If you provide your test case, I could review.
  5. #5
    then can you just tell me what I need to do in place of following code in mvc 4 as we don't have store readdata is not present in mvc 4

    protected void Store_ReadData(object sender, StoreReadDataEventArgs 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;
        }
  6. #6
    With MVC please use an AjaxProxy if you need to load data from a controller action. As here:
    http://mvc2.ext.net/#/GridPanel_Pagi...Sorting/Remote
  7. #7
    thanks for the example, I will try the example if it works out for me. also I would highly appreciate if anyone could please look into my below code and see what's wrong in it. I am trying to maintain selection of a row across pages.

    The problem with the below code is that it works fine in IE but it doesn't work in Chrome.(it is not a complete I have provided only that piece of code which I think is creating problem)

    View:
    @{
        var X = Html.X();
    }
    
    @(
            X.GridPanel()
            .Flex(1)
                .ForceFit(true).Listeners(l => { l.SelectionChange.Handler = "SelectedRowData(selected[0])"; })
            .EmptyText("No Employee Assigned.")
            .ID("grdEmployee")
                 .Cls("grdSearchPanel")
            .Store(
                    X.Store().ID("stEmployee").PageSize(10).Model(
                        X.Model().Fields(
    new ModelField("EmployeeId", ModelFieldType.String),
    new ModelField("Name", ModelFieldType.String),
    new ModelField("Type", ModelFieldType.String)
    
       
                    )
                    ).DataSource(Model)
            )
            .ColumnModel(
    
    X.Column().Text("Name").DataIndex("Name").Flex(1)
    ,
    X.Column().Text("Type").DataIndex("Type").Flex(1)
    
    )
            )
                
                )
    Controller Code:
    public ActionResult Employees(string id)
            {
                try
                {
                    
                var testRow = TempData["SelectedRow"];
                
                if (testRow != null)
                {
                    X.Js.Call("SetPageValues", testRow, employees);
                }
    
                    using (var uow = _uow.Create())
                    {
                            var data = (from e in empRep
                                        join d in department on e.DepartmentId equals id
                                        select e).ToList();
    
                            return View(data.ToList());
                    }
                        
                }
                catch (Exception)
                {
                    throw;
                }
            }

    javascript code:
    function SetPageValues(testRow, employees) {
        
        // code for setting some page data here....
    
    
    App.grdEmployee.getView().select(rowindex);
    
    
    }
    
    
    function SelectedRowData(selectedRow) {
    
        
       
        if (typeof selectedRow.data != 'undefined') {
            var data = selectedRow.data;
            EmployeeID = data.EmployeeID;
            
            if (data.DepartmentID != "") {
    
                
                if (!IsRedirectRequest) {
                    Ext.net.DirectMethod.request({
                        url: "/Employee/GetEmployees",
                        cleanRequest: true,
                        params: { DocumentId: data.EmployeeID },
                        success: function (result) {
                            
                            if (result.length != 0) {
                                App.strManager.loadData(result[0].ManagerDetails);
                            }
                            
                        }
                    });
                }
                
                IsRedirectRequest= false;
                
            }
            
        }
        else {
            //var data = selectedRow.data;
    
        }
    
    }
    Thanks
  8. #8
    I don't see any IDProperty on the Store's Model. Please set.
  9. #9
    Hi @Daniil

    Setting IDProperty doesn't solve my problem.

    Please help
  10. #10
    I am afraid we cannot help without a full test case to reproduce the problem. Please provide.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: Mar 22, 2016, 7:48 PM
  2. Replies: 9
    Last Post: Jun 23, 2015, 3:24 PM
  3. Replies: 9
    Last Post: Feb 18, 2015, 4:44 AM
  4. [CLOSED] gridpanel with remote paging maintain textfield/ numeric field values
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 27, 2013, 4:11 PM
  5. [CLOSED] gridpanel with local paging. Maintain checkbox selection while paging
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 20, 2013, 10:20 AM

Tags for this Thread

Posting Permissions