[CLOSED] issue with store.getChangedData()

  1. #1

    [CLOSED] issue with store.getChangedData()

    Hi,

    problem description:

    store.getChangedData() sends records as deleted instead of updated when filtered.

    simple scenario below

    I have a grid with three columns say name, status and code . status is A,B and C.

    Consider , I have filtered records with status 'A'. Now i try to change a record's status to 'B' . So this record would not be visible bacause of the filter .

    (But it is dirty if you clear the filter and see. ) . If I click my save button , the record is getting deleted instead of getting saved.

    While debugging I found out , store.getChangedData() is adding records to handler's deleted list instead of updated list .

    This happens only when the grid filter is applied and filtered row is changed.


    Please suggest us a solution as this needs to be fixed immediately.

    Thanks!
    Last edited by Daniil; Jul 14, 2015 at 5:21 PM. Reason: [CLOSED]
  2. #2
    Hi @vmehta,

    I could not reproduce.

    Please provide a test case.

    Please suggest us a solution as this needs to be fixed immediately.
    Just for the information. Providing us with a test case in a thread's initial post always causes the best timing of getting a solution from us.
    Last edited by Daniil; Jul 01, 2015 at 7:32 AM.
  3. #3

    getChangedData() issue

    Yes Danil. Thanks for the response .

    I have used your examples explorer code itself for reproducing this issue.
    In ext.net vs2013 solution for MVC5, look for GridPanel_Paging_and_Sorting folder under Areas
    In "LocalController" I have added the comments in the "Sync" Action.
    I have just added a list filter for "Company Column" in ~/GridPanel_Paging_and_Sorting/Views/Local/Index.cshtml.
    Please filter any value . Edit the filtered column and click save. When you debug , you will see the records under deleted section.

    Just adding those controller and cshtml file for your reference.


    @model System.Collections.IEnumerable
    @{
        ViewBag.Title = "Local paging and sorting";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @section headtag
    {
        <script>
            var count = 0; // a counter for new records
    
            function addRecord (grid) {
                grid.store.insert(0, { company : 'New' + count++ });
    
                Ext.Function.defer(function() {
                    grid.editingPlugin.startEditByPosition({row: 0, column: 0})
                }, 100); 
            }
    
            function deleteSelected (grid) {
                var store = grid.store,
                    records = grid.selModel.getSelection();
    
                store.remove(records); 
                store.load(true);
            }
    
            function selectRecord (grid, id) {
                var record = grid.store.getById(id);
                
                grid.store.loadPage(grid.store.findPage(record), {
                    callback : function () {
                        grid.getSelectionModel().select(record);
                    }
                });            
            };
            
            function exportData (grid, selectedOnly) {                        
                grid.submitData(
                    //serialization config
                    {
                       selectedOnly : selectedOnly
                    }, 
                 
                    //request config
                    {
                       isUpload:true,
                       url : '@Url.Action("Submit")'
                    }
               );
            }
            
            
        </script>
    }
    
    @section example
    {
        <h1>The following sample demonstrates local paging in the GridPanel.</h1>
            
        <p>1. Local Paging</p>
        <p>2. You can submit data from all grid's pages in one request</p>
        <p>3. If you edit data on various grid's pages then you can save in one request and changes will not be lost when you navigate beetwen pages</p>
        <p>4. Get selected data from all pages</p>
        <p>5. Navigate on page by record</p>
    
        @(
            Html.X().GridPanel()
                .Title("Plants")
                .Frame(true)
                .Width(900)
                .Height(340)
                .Store(
                    Html.X().Store()
                        .ID("Store1")
                        .DataSource(Model)
                        .Model(
                            Html.X().Model()
                                .IDProperty("company")
                                .Fields(
                                    Html.X().ModelField().Name("company"),
                                    Html.X().ModelField().Name("price").Type(ModelFieldType.Float),
                                    Html.X().ModelField().Name("change").Type(ModelFieldType.Float),
                                    Html.X().ModelField().Name("pctChange").Type(ModelFieldType.Float),
                                    Html.X().ModelField().Name("lastChange").Type(ModelFieldType.Date)
                                )
                        )
                        .PageSize(10)
                        .ServerProxy(
                            Html.X().AjaxProxy()
                                .Url(Url.Action("Read"))
                                .API(api=>api.Sync = Url.Action("Sync"))
                        )
                )
                .ColumnModel(
                    Html.X().Column()
                        .DataIndex("company")
                        .Text("Company")
                        .Flex(1)
                        .Editor(Html.X().TextField()).Filter(Html.X().ListFilter()),
                        
                    Html.X().Column()
                        .DataIndex("price")
                        .Text("Price")
                        .Width(75)
                        .Editor(Html.X().NumberField()),
                        
                    Html.X().Column()
                        .DataIndex("change")
                        .Text("Change")
                        .Width(75),
                        
                    Html.X().Column()
                        .DataIndex("pctChange")
                        .Text("Change")
                        .Width(75),
                        
                    Html.X().DateColumn()
                        .DataIndex("lastChange")
                        .Text("Last Updated")
                        .Width(85)
                        .Format("HH:mm:ss")
                )
                .SelectionModel(
                    Html.X().RowSelectionModel().Mode(SelectionMode.Multi)
                )
                .Plugins(
                    Html.X().CellEditing(),Html.X().GridFilters()
                )
                .BottomBar(
                    Html.X().PagingToolbar()
                )
                .TopBar(
                    Html.X().Toolbar()
                        .Items(
                            Html.X().Button()
                                .Text("Add record")
                                .Icon(Icon.Add)
                                .Handler("addRecord(this.up('grid'));"),
    
                            Html.X().Button()
                                .Text("Delete selected")
                                .Icon(Icon.Delete)
                                .Handler("deleteSelected(this.up('grid'));"),
                                
                            Html.X().ToolbarFill(),
                            
                            Html.X().Button()
                                .Text("Find 'Government Motors'")
                                .Icon(Icon.Find)
                                .Handler("selectRecord(this.up('grid'), 'Government Motors Corporation');"),
                                
                            Html.X().Button()
                                .Text("To XML")
                                .Icon(Icon.PageCode)
                                .Handler("exportData(this.up('grid'));"),
                                
                            Html.X().Button()
                                .Text("Selection To XML")
                                .Icon(Icon.PageCode)
                                .Handler("exportData(this.up('grid'), true);"),
                                
                            Html.X().Button()
                                .Text("Save")
                                .Icon(Icon.Disk)
                                .DirectEvents(de =>
                                {
                                    de.Click.Url = Url.Action("Sync");
                                    de.Click.ExtraParams.Add(new Parameter
                                    {
                                        Name = "data",
                                        Value = "this.up('grid').store.getChangedData()",
                                        Mode = ParameterMode.Raw,
                                        Encode = true
                                    });
                                })
                        )
                )
        )
    
        @Html.X().Label().ID("Label1")
    }
    Controller
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Ext.Net.MVC.Examples.Areas.GridPanel_Paging_and_Sorting.Models;
    using System.Xml;
    using System.Text;
    
    namespace Ext.Net.MVC.Examples.Areas.GridPanel_Paging_and_Sorting.Controllers
    {
        public class LocalController : Controller
        {
            public ActionResult Index()
            {
                return View(Companies.GetAllCompanies());
            }
    
            public ActionResult Read()
            {
                return this.Store(Companies.GetAllCompanies());
            }
    
            public ActionResult Submit(SubmitHandler handler)
            {
                return this.File(new System.Text.UTF8Encoding().GetBytes(handler.Xml.OuterXml), "application/xml", "submittedData.xml");
            }
    
            public ActionResult Sync(StoreDataHandler handler)
            {
                //basically, the filtered column's value is changed it is considering it as deleted only.
                //debug here. you will get the record in deleted when filtered. not in updated. 
                
                XmlNode xml = handler.XmlData;
                StringBuilder sb = new StringBuilder();
    
                XmlNode updated = xml.SelectSingleNode("records/Updated");
    
                if (updated != null)
                {
                    sb.Append("<p>Updated:</p>");
    
                    XmlNodeList uRecords = updated.SelectNodes("record");
    
                    foreach (XmlNode record in uRecords)
                    {
                        sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
                    }
    
                    sb.Append("<br/>");
                }
    
                XmlNode inserted = xml.SelectSingleNode("records/Created");
    
                if (inserted != null)
                {
                    sb.Append("<p>Created:</p>");
    
                    XmlNodeList iRecords = inserted.SelectNodes("record");
    
                    foreach (XmlNode record in iRecords)
                    {
                        sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
                    }
    
                    sb.Append("<br/>");
                }
    
                XmlNode deleted = xml.SelectSingleNode("records/Deleted");
    
                if (deleted != null)
                {
                    sb.Append("<p>Deleted:</p>");
    
                    XmlNodeList dRecords = deleted.SelectNodes("record");
    
                    foreach (XmlNode record in dRecords)
                    {
                        sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
                    }
    
                    sb.Append("<br/>");
                }
    
                this.GetCmp<Store>("Store1").CommitChanges();
                this.GetCmp<Label>("Label1").Html = sb.ToString();
    
                return this.Direct();
            }
        }
    }
    Model
    using System;
    using System.Collections;
    
    namespace Ext.Net.MVC.Examples.Areas.GridPanel_Paging_and_Sorting.Models
    {
        public class Companies
        {
            public static IEnumerable GetAllCompanies()
            {
                DateTime now = DateTime.Now;
    
                return new object[]
                    {
                        new object[] { "3m Co", 71.72, 0.02, 0.03, now },
                        new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, now },
                        new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, now },
                        new object[] { "American Express Company", 52.55, 0.01, 0.02, now },
                        new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, now },
                        new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, now },
                        new object[] { "Boeing Co.", 75.43, 0.53, 0.71, now },
                        new object[] { "Caterpillar Inc.", 67.27, 0.92, 1.39, now },
                        new object[] { "Citigroup, Inc.", 49.37, 0.02, 0.04, now },
                        new object[] { "E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28, now },
                        new object[] { "Exxon Mobil Corp", 68.1, -0.43, -0.64, now },
                        new object[] { "General Electric Company", 34.14, -0.08, -0.23, now },
                        new object[] { "Government Motors Corporation", 30.27, 1.09, 3.74, now },
                        new object[] { "Hewlett-Packard Co.", 36.53, -0.03, -0.08, now },
                        new object[] { "Honeywell Intl Inc", 38.77, 0.05, 0.13, now },
                        new object[] { "Intel Corporation", 19.88, 0.31, 1.58, now },
                        new object[] { "International Business Machines", 81.41, 0.44, 0.54, now },
                        new object[] { "Johnson & Johnson", 64.72, 0.06, 0.09, now },
                        new object[] { "JP Morgan & Chase & Co", 45.73, 0.07, 0.15, now },
                        new object[] { "McDonald\"s Corporation", 36.76, 0.86, 2.40, now },
                        new object[] { "Merck & Co., Inc.", 40.96, 0.41, 1.01, now },
                        new object[] { "Microsoft Corporation", 25.84, 0.14, 0.54, now },
                        new object[] { "Pfizer Inc", 27.96, 0.4, 1.45, now },
                        new object[] { "The Coca-Cola Company", 45.07, 0.26, 0.58, now },
                        new object[] { "The Home Depot, Inc.", 34.64, 0.35, 1.02, now },
                        new object[] { "The Procter & Gamble Company", 61.91, 0.01, 0.02, now },
                        new object[] { "United Technologies Corporation", 63.26, 0.55, 0.88, now },
                        new object[] { "Verizon Communications", 35.57, 0.39, 1.11, now },
                        new object[] { "Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, now }
                    };
            }
        }
    }
    Last edited by vmehta; Jul 01, 2015 at 8:37 AM.
  4. #4
    Thank you for the test case. I've reproduce the problem with Ext.NET 3.1, but it is not reproducible with the latest Ext.NET from SVN trunk. You could update. Generally, our recent upgrade to ExtJS 5.1.1 fixed quite a bunch of bugs.

    Running the test case and following the steps with the latest Ext.NET nothing is being sent to server, because everything is filtered out. To me that is quite the expected behavior of .getChangedData(). It doesn't take filtered out records into account.
    Last edited by Daniil; Jul 06, 2015 at 3:44 PM.
  5. #5

    latest svn trunk

    Hi Danil,

    Thanks for the response.

    Is there any way to get the compliled binaries from the SVN trunk ??
    If not , please suggest us how to get the latest and update it in our project.
  6. #6
    Is there any way to get the compliled binaries from the SVN trunk ??
    Unfortunately, no. Sorry for the inconvenience.

    If not , please suggest us how to get the latest and update it in our project.
    Please read:
    http://ext.net/faq/#q9

    The latest Ext.NET source is in the trunk:
    http://svn.ext.net/premium/trunk

Similar Threads

  1. [CLOSED] store getChangedData not returning inserted rows
    By jstifel in forum 3.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 07, 2015, 12:13 PM
  2. Replies: 7
    Last Post: Nov 08, 2013, 3:12 AM
  3. [CLOSED] store GetChangedData does not return id field
    By jchau in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 30, 2013, 8:43 PM
  4. Replies: 0
    Last Post: May 14, 2013, 10:05 AM
  5. [CLOSED] Store GetChangedData and Phantom record confusion
    By jchau in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 21, 2013, 7:12 AM

Posting Permissions