[CLOSED] Retaining grid filter on cell editing

  1. #1

    [CLOSED] Retaining grid filter on cell editing

    Hello,

    I am loading a grid and saving the data on cell edit. I have been doing this with the help of this example "Editable GridPanel With Save To [DirectMethod]". I also have filter headers tof ilter data. When I filter the data and then change a column value, the grid saves the cell changes and loads removing the filter conditions. Is there a way to retain the filters/sorting even after the grid is loaded after save.
    Last edited by Daniil; Oct 14, 2014 at 12:54 PM. Reason: [CLOSED]
  2. #2
    Hi @vmehta,

    Do you use local sorting and filtering? If so, you should save the sort and filtering state before saving and restore it after.

    For example, you can retrieve currently applied sorters:
    store.getSorters()
    Then I would try to re-apply it using a Store's sort method.
    Last edited by Daniil; Oct 08, 2014 at 2:46 PM.
  3. #3
    Yes, I am using local filters and sorters. There is no issue with the sorters. Even without saving sorters, it gets sorted after editing.
    Is there a way to get the filters before editing and then apply them?
  4. #4

    Sample

    Here is the sample of how I do filtering. When data is filtered and then a cell is edited, the grid is refreshed and filter is removed.
    All the records without filter is loaded.

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        public class Company
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public double Price { get; set; }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.BindData();
            }
        }
    
        private void BindData()
        {
            Store store = this.GridPanel1.GetStore();
            store.DataSource = this.GetData();
            store.DataBind();
        }
    
        private List<Company> GetData()
        {
            DateTime today = DateTime.Today;
            
            return new List<Company> 
            {
                new Company { ID = 1, Name = "3m Co", Price = 71.72 },
                new Company { ID = 2, Name = "Alcoa Inc", Price = 29.01},
                new Company { ID = 3, Name = "Altria Group Inc", Price = 83.81},
                new Company { ID = 4, Name = "American Express Company", Price = 52.55},
                new Company { ID = 5, Name = "American International Group, Inc.", Price = 64.13},
                new Company { ID = 6, Name = "AT&T Inc.", Price = 31.61},
                new Company { ID = 7, Name = "Boeing Co.", Price = 75.43},
               
            };
        }
    
        [DirectMethod(Namespace = "CompanyX")]
        public void Edit(int id, string field, string oldValue, string newValue, object customer)
        {
            this.BindData();
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Editor with DirectMethod - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />    
    
        <script>
            var edit = function (editor, e) {
               
                if (!(e.value === e.originalValue || (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {
                    CompanyX.Edit(e.record.data.ID, e.field, e.originalValue, e.value, e.record.data);
                }
            };
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:GridPanel 
                ID="GridPanel1"
                runat="server" 
                Width="600" 
                Height="350">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" Type="Int" />
                                    <ext:ModelField Name="Name" />
                                    <ext:ModelField Name="Price" Type="Float" />
                                   
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" Width="35" />
                        <ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" Flex="1">
                            <Editor>
                                <ext:TextField ID="TextField1" runat="server" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ID="Column3" runat="server" Text="Price" DataIndex="Price">
                            <Renderer Format="UsMoney" />
                            <Editor>
                                <ext:NumberField ID="NumberField1" runat="server" />
                            </Editor>
                        </ext:Column>
                     
                       
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:CellSelectionModel ID="CellSelectionModel1" runat="server" />
                </SelectionModel>
                <Plugins>
                    <ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1">
                        <Listeners>
                            <Edit Fn="edit" />
                        </Listeners>
                    </ext:CellEditing>
                    <ext:FilterHeader ID="FilterHeader1" runat="server" />
                </Plugins>
                 
            </ext:GridPanel>    
        </form>      
    </body>
    </html>
  5. #5
    Thank you for the test case.

    Please try this.
    [DirectMethod(Namespace = "CompanyX")]
    public void Edit(int id, string field, string oldValue, string newValue, object customer)
    {
        this.BindData();
        this.FilterHeader1.ApplyFilter();
    }

Similar Threads

  1. Replies: 5
    Last Post: Apr 16, 2016, 6:54 PM
  2. [CLOSED] Custom Validation in grid cell Editing
    By RajivDutt in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 14, 2014, 5:32 PM
  3. [CLOSED] Cell editing in the data grid
    By RRD in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 19, 2013, 7:01 PM
  4. Grid Panel Cell Editing focus in CheckColumn
    By shaileshsakaria in forum 2.x Help
    Replies: 3
    Last Post: Apr 27, 2013, 11:58 AM
  5. Grid Panel Cell Editing focus
    By shaileshsakaria in forum 2.x Help
    Replies: 0
    Last Post: Jan 13, 2013, 9:14 AM

Posting Permissions