[CLOSED] filter + dirty row + grid

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] filter + dirty row + grid

    Hi Team,

    One behavior we noticed in ext.net 3.1 + .
    scenario:
    Consider a grid with 3 columns. Say, A,B and C and C. C has values (high, medium, low). And it is filtered to show only 'high' values.
    if u add a new record which adds high by default ,the row appears since it is filtered by high. If it is for different value it is not appearing because of the filter.
    You can try this any of the ext.net samples with filter headers and add record functionality. If needed you shall take the code from my earlier post and filter the company column . Link below:
    http://forums.ext.net/showthread.php...tChangedData()

    In short, the dirty rows are also included as part of filters whereas in ext.net 2.5 dirty rows are not part of filters. We feel the way it behaves in 2.5 is right. We would like to know if there is any behavior change in this?

    If so we would like to get an override so that it shall behave like Ver. 2.5 itself.

    Thanks!
    Last edited by Daniil; Aug 17, 2015 at 11:36 AM. Reason: [CLOSED]
  2. #2
    Hello @vmehta!

    Use this override to attain the desired behavior:
            Ext.define('Ext.util.Collection_overrides', {
                override: 'Ext.util.Collection',
                onCollectionAdd: function (source, details) {
                    var me = this,
                        atItem = details.atItem,
                        items = details.items,
                        requestedIndex = me.requestedIndex,
                        filtered, index, copy, i, item, n;
    
                    if (!me.sorted) {
                        if (requestedIndex !== undefined) {
                            index = requestedIndex;
                        } else if (atItem) {
                            index = me.indexOf(atItem);
                            if (index === -1) {
                                index = me.findInsertIndex(items[0]);
                            } else {
                                ++index;
                            }
                        } else {
                            index = 0;
                        }
                    }
    
                    if (me.getAutoFilter() && me.filtered) {
                        for (i = 0, n = items.length; i < n; ++i) {
                            item = items[i];
                            if (copy) {
                                copy.push(item);
                            }
                        }
                    }
    
                    me.splice((index < 0) ? me.length : index, 0, copy || items);
                },
                itemChanged: function (item, modified, oldKey, meta) {
                    var me = this,
                        keyChanged = oldKey === 0 || !!oldKey,
                        filtered = me.filtered && me.getAutoFilter(),
                        filterChanged = false,
                        itemMovement = 0,
                        items = me.items,
                        last = me.length - 1,
                        sorted = me.sorted && last > 0 && me.getAutoSort(),
                        source = me.getSource(),
                        toAdd,
                        toRemove = 0,
                        index,
                        newIndex,
                        wasFiltered = false,
                        details, newKey, sortFn;
    
                    if (source && !source.updating) {
                        source.itemChanged(item, modified, oldKey, meta);
                    } else {
                        newKey = me.getKey(item);
                        if (filtered) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            wasFiltered = (index < 0);
                        }
    
                        if (wasFiltered) {
                            toAdd = [
                                item
                            ];
                            newIndex = me.length;
                        }
                        else if (sorted) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            sortFn = me.getSortFn();
    
                            if (index && sortFn(items[index - 1], items[index]) > 0) {
                                itemMovement = -1;
                                newIndex = Ext.Array.binarySearch(items, item, 0, index, sortFn);
                            } else if (index < last && sortFn(items[index], items[index + 1]) > 0) {
                                itemMovement = 1;
                                newIndex = Ext.Array.binarySearch(items, item, index + 1, sortFn);
                            }
    
                            if (itemMovement) {
                                toAdd = [
                                    item
                                ];
                            }
                        }
    
                        details = {
                            item: item,
                            key: newKey,
                            index: newIndex,
                            filterChanged: wasFiltered,
                            keyChanged: keyChanged,
                            indexChanged: !!itemMovement,
                            filtered: false,
                            oldIndex: index,
                            newIndex: newIndex,
                            wasFiltered: wasFiltered,
                            meta: meta
                        };
    
                        if (keyChanged) {
                            details.oldKey = oldKey;
                        }
    
                        if (modified) {
                            details.modified = modified;
                        }
    
                        me.beginUpdate();
                        me.notify('beforeitemchange', [
                            details
                        ]);
    
                        if (keyChanged) {
                            me.updateKey(item, oldKey);
                        }
    
                        if (toAdd || toRemove) {
                            me.splice(newIndex, toRemove, toAdd);
                        }
    
                        if (itemMovement > 0) {
                            details.newIndex--;
                        } else if (itemMovement < 0) {
                            details.oldIndex++;
                        }
    
                        me.notify('itemchange', [details]);
                        me.endUpdate();
                    }
                },
            });
    Testing playground:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="59863-dontFilterOnAdd.aspx.cs" Inherits="ExtNetPlaygroundMVC3.aspEngine._59863_dontFilterOnAdd" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = new List<object> { 
                    new {Id = 1, Company = "C1"},
                    new {Id = 2, Company = "C2"},
                    new {Id = 3, Company = "C3"},
                    new {Id = 4, Company = "C4"},
                    new {Id = 5, Company = "C5"},
                    new {Id = 6, Company = "C6"}                
                };
                this.Store1.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Custom Behaviour for FilterHeader - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
    
        <script>
            Ext.net.FilterHeader.behaviour.addBehaviour("string", {
                name: "any",
    
                is: function (value) {
                    return Ext.net.StringUtils.startsWith(value, "any ");
                },
    
                getValue: function (value) {
                    var values = Ext.net.FilterHeader.behaviour.getStrValue(value).substring(4).split(" "),
                        tmp = [];
    
                    Ext.each(values, function (v) {
                        v = v.trim();
                        if (!Ext.isEmpty(v)) {
                            tmp.push(v);
                        }
                    });
    
                    values = tmp;
    
                    return { value: values, valid: values.length > 0 };
                },
    
                match: function (recordValue, matchValue) {
                    for (var i = 0; i < matchValue.length; i++) {
                        if (recordValue === matchValue[i]) {
                            return true;
                        }
                    }
                    return false;
                },
    
                isValid: function (value) {
                    return this.getValue(value, field).valid;
                },
    
                serialize: function (value) {
                    return {
                        type: "string",
                        op: "any",
                        value: value
                    };
                }
            });
    
            function indexOf(company) {
                return App.Store1.findBy(function (z) { if (z.get('Company') == company) return true; else return false; })
            }
    
            Ext.define('Ext.util.Collection_overrides', {
                override: 'Ext.util.Collection',
                onCollectionAdd: function (source, details) {
                    var me = this,
                        atItem = details.atItem,
                        items = details.items,
                        requestedIndex = me.requestedIndex,
                        filtered, index, copy, i, item, n;
    
                    if (!me.sorted) {
                        if (requestedIndex !== undefined) {
                            index = requestedIndex;
                        } else if (atItem) {
                            index = me.indexOf(atItem);
                            if (index === -1) {
                                index = me.findInsertIndex(items[0]);
                            } else {
                                ++index;
                            }
                        } else {
                            index = 0;
                        }
                    }
    
                    if (me.getAutoFilter() && me.filtered) {
                        for (i = 0, n = items.length; i < n; ++i) {
                            item = items[i];
                            if (copy) {
                                copy.push(item);
                            }
                        }
                    }
    
                    me.splice((index < 0) ? me.length : index, 0, copy || items);
                },
                itemChanged: function (item, modified, oldKey, meta) {
                    var me = this,
                        keyChanged = oldKey === 0 || !!oldKey,
                        filtered = me.filtered && me.getAutoFilter(),
                        filterChanged = false,
                        itemMovement = 0,
                        items = me.items,
                        last = me.length - 1,
                        sorted = me.sorted && last > 0 && me.getAutoSort(),
                        source = me.getSource(),
                        toAdd,
                        toRemove = 0,
                        index,
                        newIndex,
                        wasFiltered = false,
                        details, newKey, sortFn;
    
                    if (source && !source.updating) {
                        source.itemChanged(item, modified, oldKey, meta);
                    } else {
                        newKey = me.getKey(item);
                        if (filtered) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            wasFiltered = (index < 0);
                        }
    
                        if (wasFiltered) {
                            toAdd = [
                                item
                            ];
                            newIndex = me.length;
                        }
                        else if (sorted) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            sortFn = me.getSortFn();
    
                            if (index && sortFn(items[index - 1], items[index]) > 0) {
                                itemMovement = -1;
                                newIndex = Ext.Array.binarySearch(items, item, 0, index, sortFn);
                            } else if (index < last && sortFn(items[index], items[index + 1]) > 0) {
                                itemMovement = 1;
                                newIndex = Ext.Array.binarySearch(items, item, index + 1, sortFn);
                            }
    
                            if (itemMovement) {
                                toAdd = [
                                    item
                                ];
                            }
                        }
    
                        details = {
                            item: item,
                            key: newKey,
                            index: newIndex,
                            filterChanged: wasFiltered,
                            keyChanged: keyChanged,
                            indexChanged: !!itemMovement,
                            filtered: false,
                            oldIndex: index,
                            newIndex: newIndex,
                            wasFiltered: wasFiltered,
                            meta: meta
                        };
    
                        if (keyChanged) {
                            details.oldKey = oldKey;
                        }
    
                        if (modified) {
                            details.modified = modified;
                        }
    
                        me.beginUpdate();
                        me.notify('beforeitemchange', [
                            details
                        ]);
    
                        if (keyChanged) {
                            me.updateKey(item, oldKey);
                        }
    
                        if (toAdd || toRemove) {
                            me.splice(newIndex, toRemove, toAdd);
                        }
    
                        if (itemMovement > 0) {
                            details.newIndex--;
                        } else if (itemMovement < 0) {
                            details.oldIndex++;
                        }
    
                        me.notify('itemchange', [details]);
                        me.endUpdate();
                    }
                },
            });
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" SourceFormatting="true" />
    
            <h1>Custom Behaviour for FilterHeader</h1>
    
            <p>This examples demonstrates how to add custom behaviour for filtering</p>
            <p>Custom behaviour: search any of values from list (string filter)</p>
            <p>Example: any C1 C2</p>
    
            <ext:Window
                ID="Window1"
                runat="server"
                Width="400"
                Height="250"
                Closable="false"
                Title="Example"
                Layout="Fit">
                <Items>
                    <ext:GridPanel runat="server">
                        <Store>
                            <ext:Store ID="Store1" runat="server">
                                <Model>
                                    <ext:Model runat="server" IDProperty="Id">
                                        <Fields>
                                            <ext:ModelField Name="Id" Type="Int" />
                                            <ext:ModelField Name="Company" Type="String" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                        <ColumnModel runat="server">
                            <Columns>
                                <ext:Column runat="server" Text="ID" DataIndex="Id" Filterable="false" Width="40" />
                                <ext:Column runat="server" Text="Company" DataIndex="Company" Flex="1">
                                    <Editor>
                                        <ext:TextField runat="server" />
                                    </Editor>
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <Plugins>
                            <ext:FilterHeader runat="server" />
                            <ext:CellEditing runat="server" AutoDataBind="true" />
                        </Plugins>
                        <BottomBar>
                            <ext:Toolbar runat="server">
                                <Items>
                                    <ext:Button runat="server" Text="Filter Set 1" Handler="this.up('grid').filterHeader.setValue({Company: 'any C1 C3'});" />
                                    <ext:Button runat="server" Text="Filter Set 2" Handler="this.up('grid').filterHeader.setValue({Company: 'any C2 C4'});" />
                                </Items>
                            </ext:Toolbar>
                        </BottomBar>
                    </ext:GridPanel>
                </Items>
            </ext:Window>
            <ext:Button runat="server" Text="Filter C1*" Handler="App.Window1.down('grid').filterHeader.setValue({Company: 'C1'});" />
            <ext:Button runat="server" Text="Add C10" Handler="App.Store1.addSorted({Id: '10', Company: 'C10'});" />
            <ext:Button runat="server" Text="Add C20" Handler="App.Store1.addSorted({Id: '20', Company: 'C20'});" />
            <ext:Button runat="server" Text="Rename C3 to C15" Handler="App.Store1.query('Company','C3').first().set('Company', 'C15')" />
            <ext:Button runat="server" Text="Rename C5 to C35" Handler="App.Store1.query('Company','C5').first().set('Company', 'C35')" />
            <ext:Button runat="server" Text="Rename C10 to C25" Handler="App.Store1.query('Company','C10').first().set('Company', 'C25')" />
            <ext:Button runat="server" Text="Clear filter" Handler="App.Window1.down('grid').filterHeader.setValue({Company: ''});" />
        </form>
    </body>
    </html>
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello,

    Thanks for the response. Anyway, that didn't help our case. When I added that override it messed up our screen. i.e. the first time i click a cell with combobox editor it moves to the left of the page and after that I'm not able to do further operations.
    FYI, we have a grid with combination of text field and combobox editors. Also we have list filters in our grid.
    One more info is we do not use filter header, instead we use column filters.

    Hope it explains our case.

    Also, Do we really need to override the whole collection itself to get this working as the previous version?


    Thanks!
  4. #4
    Hello again @vmehta!

    Well, I guess we would need you to provide a sample runnable case using the resources you need if we are to give you helpful advices. If possible, of course. Could you reproduce the view with some fake data and provide us with the sample code like the one I provided?

    If in doubt on how to come up with a simple runnable example, please refer to these posts:
    - Forum Guidelines For Posting New Topics
    - More information required

    About the huge override, no, its not always necessary to override a lot of code, just that in this case the exact methods to handle added and changed records were quite long. Spending a little more time I believe it would be possible to come up with much shorter overrides. This was the least intrusive override I could come up with, avoiding the code to redo unnecessary work (thus not impacting performance negatively when we are removing functionality -- not adding).
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello @fabricio,

    I have somehow created a runnable sample which reproduces the issue even after overriding the collection. i.e. dirty rows are getting filtered if the column filter is applied already. In the sample below click on the filters option on the column size. Just check the "large" option. The grid would filter as expected. Try to change the large as small . The record becomes dirty because of change but disappears. We do not want the dirty rows to be filtered. (which is the behavior in ext.net 2.5). Anyway I have a sample to reproduce now, but in our actual code, grid is not responsive at all after the override is applied. I have tried multiple times with / without this override. It simply throws "cannot set z index on undefined". I don't have clue of this when i combine this message with the override. !!!

    Anyway, hopefully this sample should help you understand our requirement better.
    Thanks!

    Controller:
    namespace Ext.Net.MVC.Examples.Areas.GridPanel_FilterHeader.Controllers
    {
        public class OverviewController : Controller
        {
            public ActionResult Index()
            {
                return View(new List<object>{
                    new
                        {
                            Id = 1,
                            Price = 71.72,
                            Company = "3m Co",
                            Date = new DateTime(2007, 9, 1),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 2,
                            Price = 29.01,
                            Company = "Aloca Inc",
                            Date = new DateTime(2007, 08, 01),
                            Size = "medium",
                            Visible = false
                        },
                    new
                        {
                            Id = 3,
                            Price = 83.81,
                            Company = "Altria Group Inc",
                            Date = new DateTime(2007, 08, 03),
                            Size = "large",
                            Visible = false
                        },
                    new
                        {
                            Id = 4,
                            Price = 52.55,
                            Company = "American Express Company",
                            Date = new DateTime(2008, 01, 04),
                            Size = "extra large",
                            Visible = true
                        },
                    new
                        {
                            Id = 5,
                            Price = 64.13,
                            Company = "American International Group Inc.",
                            Date = new DateTime(2008, 03, 04),
                            Size = "small",
                            Visible = true
                        },
                    new
                        {
                            Id = 6,
                            Price = 31.61,
                            Company = "AT&T Inc.",
                            Date = new DateTime(2008, 02, 01),
                            Size = "extra large",
                            Visible = false
                        },
                    new
                        {
                            Id = 7,
                            Price = 75.43,
                            Company = "Boeing Co.",
                            Date = new DateTime(2008, 01, 01),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 8,
                            Price = 67.27,
                            Company = "Caterpillar Inc.",
                            Date = new DateTime(2007, 12, 03),
                            Size = "medium",
                            Visible = true
                        },
                    new
                        {
                            Id = 9,
                            Price = 49.37,
                            Company = "Citigroup, Inc.",
                            Date = new DateTime(2007, 11, 24),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 10,
                            Price = 40.48,
                            Company = "E.I. du Pont de Nemours and Company",
                            Date = new DateTime(2007, 05, 09),
                            Size = "extra large",
                            Visible = false
                        },
                    new
                        {
                            Id = 11,
                            Price = 68.1,
                            Company = "Exxon Mobile Corp",
                            Date = new DateTime(2007, 12, 12),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 12,
                            Price = 34.14,
                            Company = "General Electric Company",
                            Date = new DateTime(2008, 06, 16),
                            Size = "extra large",
                            Visible = true
                        },
                    new
                        {
                            Id = 13,
                            Price = 30.27,
                            Company = "General Motors Corporation",
                            Date = new DateTime(2006, 12, 07),
                            Size = "medium",
                            Visible = true
                        },
                    new
                        {
                            Id = 14,
                            Price = 36.53,
                            Company = "Hewlett-Packard Co.",
                            Date = new DateTime(2007, 05, 13),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 15,
                            Price = 38.77,
                            Company = "Honweywell Intl Inc",
                            Date = new DateTime(2006, 11, 07),
                            Size = "medium",
                            Visible = false
                        },
                    new
                        {
                            Id = 16,
                            Price = 19.88,
                            Company = "Intel Corporation",
                            Date = new DateTime(2007, 01, 09),
                            Size = "small",
                            Visible = true
                        },
                    new
                        {
                            Id = 17,
                            Price = 81.41,
                            Company = "International Business Machines",
                            Date = new DateTime(2005, 01, 21),
                            Size = "extra large",
                            Visible = true
                        },
                    new
                        {
                            Id = 18,
                            Price = 64.72,
                            Company = "Johnson & Johnson",
                            Date = new DateTime(2008, 01, 10),
                            Size = "extra large",
                            Visible = true
                        },
                    new
                        {
                            Id = 19,
                            Price = 45.73,
                            Company = "JP Morgan & Chase & Co",
                            Date = new DateTime(2008, 02, 20),
                            Size = "large",
                            Visible = false
                        },
                    new
                        {
                            Id = 20,
                            Price = 36.76,
                            Company = "McDonald's Corporation",
                            Date = new DateTime(2007, 06, 12),
                            Size = "large",
                            Visible = true
                        },
                    new
                        {
                            Id = 21,
                            Price = 27.96,
                            Company = "Pfizer Inc",
                            Date = new DateTime(2007, 12, 30),
                            Size = "small",
                            Visible = false
                        },
                    new
                        {
                            Id = 22,
                            Price = 45.07,
                            Company = "The Coca-Cola Company",
                            Date = new DateTime(2007, 01, 30),
                            Size = "medium",
                            Visible = false
                        },
                    new
                        {
                            Id = 23,
                            Price = 34.64,
                            Company = "The Home Depot, Inc",
                            Date = new DateTime(2006, 12, 31),
                            Size = "small",
                            Visible = true
                        },
                    new
                        {
                            Id = 24,
                            Price = 61.91,
                            Company = "The Procter & Gamble Company",
                            Date = new DateTime(2007, 04, 08),
                            Size = "extra large",
                            Visible = true
                        },
                    new
                        {
                            Id = 25,
                            Price = 63.26,
                            Company = "United Technologies Corporation",
                            Date = new DateTime(2006, 06, 04),
                            Size = "medium",
                            Visible = true
                        },
                    new
                        {
                            Id = 26,
                            Price = 35.57,
                            Company = "Verizon Communications",
                            Date = new DateTime(2005, 07, 09),
                            Size = "small",
                            Visible = false
                        },
                    new
                        {
                            Id = 27,
                            Price = 45.45,
                            Company = "Wal-Mart Stores, Inc",
                            Date = new DateTime(2006, 09, 09),
                            Size = "large",
                            Visible = true
                        }
                });
            }
        }
    }
    View

    @using SortDirection = Ext.Net.SortDirection
    @model List<object>
    
    @{
        var X = Html.X();
        ViewBag.Title = "FilterHeader plugin overview  - Ext.NET MVC Examples";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @section headtag
    {
        <script>
            var loadFilter = function (plugin) {
                plugin.setValue({
                    Id : ">5",
                    Company: "!Inc.",
                    Price: ">50<70",
                    Visible: 1
                });
            };
            Ext.define('Ext.util.Collection_overrides', {
                override: 'Ext.util.Collection',
                onCollectionAdd: function (source, details) {
                    var me = this,
                        atItem = details.atItem,
                        items = details.items,
                        requestedIndex = me.requestedIndex,
                        filtered, index, copy, i, item, n;
    
                    if (!me.sorted) {
                        if (requestedIndex !== undefined) {
                            index = requestedIndex;
                        } else if (atItem) {
                            index = me.indexOf(atItem);
                            if (index === -1) {
                                index = me.findInsertIndex(items[0]);
                            } else {
                                ++index;
                            }
                        } else {
                            index = 0;
                        }
                    }
    
                    if (me.getAutoFilter() && me.filtered) {
                        for (i = 0, n = items.length; i < n; ++i) {
                            item = items[i];
                            if (copy) {
                                copy.push(item);
                            }
                        }
                    }
    
                    me.splice((index < 0) ? me.length : index, 0, copy || items);
                },
                itemChanged: function (item, modified, oldKey, meta) {
                    var me = this,
                        keyChanged = oldKey === 0 || !!oldKey,
                        filtered = me.filtered && me.getAutoFilter(),
                        filterChanged = false,
                        itemMovement = 0,
                        items = me.items,
                        last = me.length - 1,
                        sorted = me.sorted && last > 0 && me.getAutoSort(),
                        source = me.getSource(),
                        toAdd,
                        toRemove = 0,
                        index,
                        newIndex,
                        wasFiltered = false,
                        details, newKey, sortFn;
    
                    if (source && !source.updating) {
                        source.itemChanged(item, modified, oldKey, meta);
                    } else {
                        newKey = me.getKey(item);
                        if (filtered) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            wasFiltered = (index < 0);
                        }
    
                        if (wasFiltered) {
                            toAdd = [
                                item
                            ];
                            newIndex = me.length;
                        }
                        else if (sorted) {
                            index = me.indexOfKey(keyChanged ? oldKey : newKey);
                            sortFn = me.getSortFn();
    
                            if (index && sortFn(items[index - 1], items[index]) > 0) {
                                itemMovement = -1;
                                newIndex = Ext.Array.binarySearch(items, item, 0, index, sortFn);
                            } else if (index < last && sortFn(items[index], items[index + 1]) > 0) {
                                itemMovement = 1;
                                newIndex = Ext.Array.binarySearch(items, item, index + 1, sortFn);
                            }
    
                            if (itemMovement) {
                                toAdd = [
                                    item
                                ];
                            }
                        }
    
                        details = {
                            item: item,
                            key: newKey,
                            index: newIndex,
                            filterChanged: wasFiltered,
                            keyChanged: keyChanged,
                            indexChanged: !!itemMovement,
                            filtered: false,
                            oldIndex: index,
                            newIndex: newIndex,
                            wasFiltered: wasFiltered,
                            meta: meta
                        };
    
                        if (keyChanged) {
                            details.oldKey = oldKey;
                        }
    
                        if (modified) {
                            details.modified = modified;
                        }
    
                        me.beginUpdate();
                        me.notify('beforeitemchange', [
                            details
                        ]);
    
                        if (keyChanged) {
                            me.updateKey(item, oldKey);
                        }
    
                        if (toAdd || toRemove) {
                            me.splice(newIndex, toRemove, toAdd);
                        }
    
                        if (itemMovement > 0) {
                            details.newIndex--;
                        } else if (itemMovement < 0) {
                            details.oldIndex++;
                        }
    
                        me.notify('itemchange', [details]);
                        me.endUpdate();
                    }
                },
            });
            
        </script>
    }
    
    @section example {
        <h1>FilterHeader plugin overview</h1> 
            
        <p>FilterHeader plugin allows use the following operators:</p>
    
        <ul>
            <li>String: =(equals), +(starts with), -(ends with), *(contains), !(doesn't contain)</li>
            <li>Date: >, <, >=, <= or date for equals</li>
            <li>Number: >, <, >=, <= or date for equals</li>
            <li>Boolean: 1, 0, true, false</li>
        </ul>
        
        @(X.Window()
            .ID("Window1")
            .Width(800)
            .Height(400)
            .Closable(false)
            .Title("Example")
            .Maximizable(true)
            .Layout(LayoutType.Fit)
            .Items(
                X.GridPanel()
                    .ID("GridPanel1")
                    .Store(X.Store()
                        .ID("Store1")
                        .DataSource(Model)
                        .PageSize(10)
                        .Model(X.Model()
                            .Fields(
                                X.ModelField().Name("Id").Type(ModelFieldType.Int),
                                X.ModelField().Name("Company").Type(ModelFieldType.String),
                                X.ModelField().Name("Price").Type(ModelFieldType.Float),
                                X.ModelField().Name("Date").Type(ModelFieldType.Date),
                                X.ModelField().Name("Size").Type(ModelFieldType.String),
                                X.ModelField().Name("Visible").Type(ModelFieldType.Boolean)
                            )
                        )
                        .Sorters(X.DataSorter().Property("Company").Direction(SortDirection.ASC))
                    )
                    .ColumnModel(
                        X.Column().Text("ID").DataIndex("Id"),
                        X.Column().Text("Company").DataIndex("Company").Flex(1).Editor(Html.X().TextField()),
                        X.Column().Text("Price").DataIndex("Price").Renderer(new Renderer{Format= RendererFormat.UsMoney}),
                        X.DateColumn().Text("Date").DataIndex("Date").Align(Alignment.Center).Format("yyyy-MM-dd"),
                        X.Column().Text("Size").DataIndex("Size").Editor(Html.X().TextField()).Filter(Html.X().ListFilter()),
                        X.Column().Text("Visible").DataIndex("Visible").Align(Alignment.Center)
                            .Renderer("return (value) ? 'Yes':'No';")
                    )
                    .Plugins(
                        X.FilterHeader(),X.CellEditing().ClicksToEdit(1),X.GridFilters()
                    )
                    .BottomBar(
                        X.PagingToolbar()
                            .HideRefresh(true)
                    )
                    .DockedItems(
                        X.Toolbar()
                            .Dock(Dock.Bottom)
                            .Items(
                                X.Button()
                                    .Text("Case Sensitive")
                                    .EnableToggle(true)
                                    .AllowDepress(true)
                                    .ToggleHandler("var plugin = this.up('grid').filterHeader; plugin.caseSensitive = this.pressed; plugin.applyFilter();"),
                                X.Button()
                                    .Text("Load Filters")
                                    .Handler("loadFilter(this.up('grid').filterHeader);"),
                                X.Button()
                                    .Text("Get Fields Values")
                                    .ToolTip("Get Values of Fields")
                                    .Handler("var values = Ext.encode(this.up('grid').filterHeader.getValue()); Ext.Msg.alert('Fields Values', values);"),
                                X.Button()
                                    .Text("Get Filter Values")
                                    .ToolTip("Get Filter Values of Grid")
                                    .Handler("var filters = Ext.encode(this.up('grid').filterHeader.getFilterValues()); Ext.Msg.alert('Filter Values', filters);"),
                                X.Button()
                                    .Text("Clear Filters")
                                    .Handler("this.up('grid').filterHeader.clearFilter();")
                            )
                    )
                    .Listeners(l =>
                    {
                        l.AfterRender.Handler = "this.filterHeader.fields[0].setIconCls('#Magnifier')";
                        l.AfterRender.Delay = 10;
                    })
            )
        )
    }
  6. #6
    Team,

    Any updates for my previous post ?

    Thanks!
  7. #7
    Thank you for the test case. It takes time to investigate it. Once we are ready, we will post a follow-up. It should happen later this week.
    Last edited by Daniil; Aug 13, 2015 at 9:51 AM.
  8. #8
    Personally, the current behavior is expected to me. I mean getting rid of an edited record if it no longer matches the filter conditions.

    But I also agree that your request is absolutely fair. There should be a possibility to ignore dirty records to re-trigger filtering.

    To be honest, it was quite challenging to find a solution, but seems it is found in this override. Tested with both 3.1/3.2 and appears to be working as you need. Please try.

    Ext.util.Collection.override({
        isItemFiltered: function (item) {
            return !this.getFilters().filterFn(item) && !item.dirty; // added "&& !item.dirty"
        }
    });
    
    Ext.grid.filters.filter.List.override({
        onDataChanged: function (store) {
            if (arguments[1] && arguments[1].dirty && arguments[2] && (arguments[2] === "edit") ) {
                return; // ignore the default onDataChanged logic on edit
            }
    
            this.callParent(arguments);
        }
    });
  9. #9
    Thanks Danil. I would try this and get back to you on Monday.

    Thanks again!
  10. #10
    Hi Danil,

    Thanks for the solution. It almost solves our problem.
    Two things:

    1) We don't see the second override called at all. Can you please tell in which scenario, it would be executed. ?
    2) Also, the dirty row is maintained for all cases except the below scenario

    When any of the column in sorted by descending and if we try to add a new record, it always goes to the end of the grid.(even it has multiple pages, it goes as the last record of last page.)

    Please let us know if this information is sufficient for you to recreate.

    Thanks!
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Add new row to grid (dirty is false)
    By Z in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 06, 2014, 6:13 PM
  2. [CLOSED] is my grid dirty?
    By Z in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 20, 2014, 6:37 PM
  3. Remove red dirty flags from grid.
    By AaronB3 in forum 1.x Help
    Replies: 2
    Last Post: Jun 27, 2011, 9:47 PM
  4. How to set Grid record dirty?
    By speddi in forum 1.x Help
    Replies: 0
    Last Post: Jul 16, 2010, 8:47 PM
  5. Marking all records as dirty in a grid
    By n_s_adhikari@rediffmail.com in forum 1.x Help
    Replies: 1
    Last Post: May 10, 2010, 11:35 PM

Tags for this Thread

Posting Permissions