[CLOSED] Grid with Paging Toolbar Dirty flag

  1. #1

    [CLOSED] Grid with Paging Toolbar Dirty flag

    Hi , I am using using Version 4.7.1, but I can see same issue on version 5.3.0.0

    I have bind Grid with few records on loading page, While checking Grid has any Dirty (without doing any changes)
    on Paging Toolbar number Field showing isDirty True.

    How to make by default it is false ?
    after refresh or load Grid, it should be isDirty false flag


    for Eg : I have use the code from Web Forms Examples 5.3 -> Grid Panel -> ArrayGrid -> ArrayWithPaging
    and added a new button for check has any Dirty Child.

    my button
     <ext:Button runat="server" Text="CheckDirty" ItemID="btnCheckDirty">
    		                    <Listeners>
    			                    <Click Handler="hasDirtyChild()"></Click>
    		                    </Listeners>
    	                    </ext:Button>
    I have used this function for check any dirty

    
    var hasDirtyChild = function() {
    
    var grid = App.GridPanel1;
    Ext.each(grid.query('*'), function (item) {
    if (item.isDirty && item.isDirty()) {
    ret = true;
    }
    });
    }
    it is returning true because of Paging Toolbar number Field is dirty
    Last edited by fabricio.murta; Jul 19, 2021 at 1:15 PM. Reason: Resolved.
  2. #2
    Hello @lousberg, and welcome to Ext.NET Forums!

    I believe the problem is that you are just checking everything that's inside the grid panel. Well, the paging toolbar is, in fact, inside the grid pannel, docked as a "bottom bar".

    So the result you are getting seems correct. You probably want to check instead if the grid's store is dirty. So, instead of looping around, you could just App.GridPanel1.getStore().isDirty(). Doesn't it do what you need?

    Notice that's not an Ext JS feature; this isDirty() check straight from the Store is an Ext.NET feature implemented exactly because Ext JS didn't have some practical means to check for a given store's dirty state.

    These two examples use the mechanism:
    - GridPanel > Miscellaneous > Save_Filter
    - GridPanel > Update > Batch

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks for your replay,

    it helps only for check is there any dirty on Grid, In real situation I can't avoid this for loop because I need to check has any dirty inside my Container and that container having lot of other controls not only this grid with paging.

    In my given code of example I have added only the example of Grid because it was returning isDirty true from Paging Tool bar.

    here I can give another example
    In my "hasDirtyChild" funciton I am passing my container and checking is there any dirty

    function hasDirtyChild(cnt) {
    		
    		if (!cnt)
    			return false;
    
    		var ret = false;
    		Ext.each(cnt.query('*'), function (item) {
    			if (item.isDirty && item.isDirty()) {				
    				ret = true;
    			}
    		});
    		
    		return ret;
    	}
  4. #4
    Hi, I have tried to check with store.isDirty from container items,
    if item from container having store then checking "if (item.store.isDirty())"
    else checking "item.isDirty()"

    but still it is returning isDirty true from paging tool bar (Number field),
    is there any way I can skip checking paging tool bar from this loop ?

    I am adding coding sample below

    
    function hasDirtyChild(cnt) {
    		debugger;
    		if (!cnt)
    			return false;
    
    		var ret = false;
    		Ext.each(cnt.query('*'), function (item) {
    			if (item.store) {
    				if (item.store.isDirty()) {
    					debugger;
    					ret = true;
    				}
    			}
    			else
    			{
    				if (item.isDirty && item.isDirty()) {
    				debugger;
    				ret = true;
    			}}
    		});
    }
  5. #5
    Hello, @lousberg!

    Please provide a full simplified test case with the scenario you are trying to reproduce so we can properly give you a solution for the problem.

    Until you can provide a test case, all we can say is that one of the possible solutions then is to check if that item is within the paging toolbar and ignore it. Maybe more robust would be to evaluate only and only items exactly within a given context/container and not recurse down.

    Your use case is very specific and we won't be able to tell how you should proceed unless we can reproduce the scenario in our side.

    If in doubt how to come up with test case, please take your time to review threads we have dedicated to clearing that up:

    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    I believe you could base your test case off the Paging GridPanel example, and maybe with bits from this FormPanel one.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  6. #6

    simplified test case

    Hi I have added my simplified test case code below,
    there is a button "Check Dirty" (it is checking is any Dirty inside Container)
    click the button, you can see alert message which is isDirty true
    (without doing any changes)

    
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.BindData();
            }
        }
    	
        private void BindData()
        {
            Store store = this.GridPanel1.GetStore();
    
            store.DataSource = this.Data;
            store.DataBind();
        }
    
        private object[] Data
        {   
            get
            {
    	        return new object[]
                {
                    new object[] { "3m Co" },
                    new object[] { "Alcoa Inc"},
                    
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
    	<script>
    		var hasDirtyChild = function () {
    			var cont = App.container1;
    			Ext.each(cont.query('*'), function(item) {
                    if (item.isDirty && item.isDirty()) {
    					ret = true;
    					alert(item.id);
                    }
    		    });
    	    }
    	</script>
        
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Container runat="server" ItemID="container1" ID="container1">
    	        <Items>
    				<ext:TextField runat="server" FieldLabel="Name" Text="Alex" ></ext:TextField>
    	           
    	            <ext:GridPanel
    		            ID="GridPanel1"
    		            runat="server"
    		            Title="Array Grid"
    		            Width="800">
    		            <Store>
    			            <ext:Store ID="Store1" runat="server"  PageSize="10">
    				            <Model>
    					            <ext:Model runat="server">
    						            <Fields>
    							            <ext:ModelField Name="company" />
    						            </Fields>
    					            </ext:Model>
    				            </Model>
    			            </ext:Store>
    		            </Store>
    		            <ColumnModel runat="server">
    			            <Columns>
    				            <ext:RowNumbererColumn runat="server" Width="35" />
    				            <ext:Column runat="server" Text="Company" DataIndex="company" Flex="1" />
    			            </Columns>
    		            </ColumnModel>
    		            <BottomBar>
    			            <ext:PagingToolbar runat="server">
    				            <Items>
    				            </Items>
    			            </ext:PagingToolbar>
    		            </BottomBar>
    		          
    	            </ext:GridPanel>
    				
    		        <ext:Button runat="server" Text="Check Dirty" >
    			        <Listeners>
    				        <Click Handler="hasDirtyChild()"></Click>
    			        </Listeners>
    		        </ext:Button>
                </Items>
            </ext:Container>
        </form>
    </body>
    </html>
  7. #7
    Hello @lousberg! Thanks for the test case!

    Option 1: Exclude what's inside the paging toolbar:

    item.isDirty && item.isDirty() && !item.up().is('pagingtoolbar')

    Option 2: Use ext:FormPanel instead of ext:Container!

    Then you check if the form panel is dirty; it will traverse any form fields within it to check whether they have been changed since load or last commit!.. Well, and the grid panel (or probably panels) you have, then you can use a selector just for them. Here's your test case with a bit of expansion with what I believe you may have (like fields within fields, and an assortment of grid panels).

    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.BindData();
            }
        }
    	
        private void BindData()
        {
            Store store = this.GridPanel1.GetStore();
    
            store.DataSource = this.Data;
            store.DataBind();
        }
    
        private object[] Data
        {   
            get
            {
    	        return new object[]
                {
                    new object[] { "3m Co" },
                    new object[] { "Alcoa Inc"},
                    
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
    	<title>63165 - Grid with Paging Toolbar Dirty flag</title>
    	<script>
    		var hasDirtyChild = function () {
    			var cont = App.container1;
    			var ret = false;
    			if (cont.isDirty()) {
    				ret = true;
    				Ext.toast("Form panel is dirty.");
    			}
    
    			Ext.each(cont.query('gridpanel'), function (item) {
                    if (item.getStore().isDirty()) {
                        ret = true;
                        Ext.toast('Dirty: ' + item.id);
                    }
                });
    
    			if (!ret) Ext.toast('All clean.');
    	    }
        </script>
        
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:FormPanel runat="server" ItemID="container1" ID="container1">
    	    <Items>
    			<ext:TextField runat="server" FieldLabel="Name" Text="Alex" />
    	        <ext:TextField runat="server" FieldLabel="Address" Text="Their street" />
    			<ext:FieldSet runat="server" Title="Sub items">
    				<Items>
    					<ext:TextField runat="server" FieldLabel="Item 1" Text="Value 1" />
    					<ext:TextField runat="server" FieldLabel="Item 2" Text="Value 2" />
    					<ext:TextField runat="server" FieldLabel="Item 3" Text="Value 3" />
    				</Items>
    			</ext:FieldSet>
    			<ext:NumberField runat="server" FieldLabel="Amount" Text="7" />
    			<ext:Checkbox runat="server" FieldLabel="Is ready" Text="false" />
    	        <ext:GridPanel
    		        ID="GridPanel1"
    		        runat="server"
    		        Title="Array Grid"
    		        Width="800">
    		        <Store>
    			        <ext:Store ID="Store1" runat="server"  PageSize="10">
    				        <Model>
    					        <ext:Model runat="server">
    						        <Fields>
    							        <ext:ModelField Name="company" />
    						        </Fields>
    					        </ext:Model>
    				        </Model>
    			        </ext:Store>
    		        </Store>
    		        <ColumnModel runat="server">
    			        <Columns>
    				        <ext:RowNumbererColumn runat="server" Width="35" />
    				        <ext:Column runat="server" Text="Company" DataIndex="company" Flex="1">
    							<Editor>
    								<ext:TextField runat="server" />
    							</Editor>
    				        </ext:Column>
    			        </Columns>
    		        </ColumnModel>
    		        <BottomBar>
    			        <ext:PagingToolbar runat="server">
    				        <Items>
    				        </Items>
    			        </ext:PagingToolbar>
    		        </BottomBar>
    				<Plugins>
    					<ext:CellEditing runat="server" />
    				</Plugins>
    	        </ext:GridPanel>
    				
    		    <ext:Button runat="server" Text="Check Dirty" >
    			    <Listeners>
    				    <Click fn="hasDirtyChild"></Click>
    			    </Listeners>
    		    </ext:Button>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    Okay, I haven't really included the assortment of grid panels here, I think it would just make the sample long; we use the selector to find grid panels and it may be enough -- as long as you are nesting the grid panels within the container1 (which I kept the ID despite changing into a FormPanel).

    These are not the only options; you can also fancy an advanced Ext.ComponentQuery to the container and make the selection excluding whatever else may be getting misleading dirty values... Well, and who knows what else could be done for that goal... I am just showing a few options that came to mind.

    In case you are wondering why the number field in the paging toolbar is becoming "dirty" although you didn't change it, the answer is, Ext.NET changes it on load. It may not be exactly this, but roughly, the page counter is initially empty and the paging logic fills them as it determines the amount of pages and ensures it is in the first one. Paging toolbar is designed for remote data and although it looks very simple with Ext.NET code, a considerable amount of sugar has been added to the syntax (and extensions) to make that possible. So it never loses its "dynamic" aspect.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  8. #8
    Thanks Fabricio!
    Please close this thread.
  9. #9
    Hello @lousberg, and thanks for the follow up! Glad one of the solutions helped or shown the right direction to make your page work the way you needed!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Grid with Paging Toolbar Dirty flag
    By shimith in forum 4.x Help
    Replies: 2
    Last Post: Jul 08, 2021, 10:15 AM
  2. [CLOSED] insert to grid store not showing red dirty flag
    By susanz in forum 4.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 27, 2017, 1:50 PM
  3. [CLOSED] set dirty flag
    By Z in forum 3.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 16, 2015, 12:18 PM
  4. [CLOSED] enable dirty flag for new row added to grid
    By susanz in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 07, 2014, 2:13 AM
  5. Adding SelectedItem to Combobox sets the Dirty Flag
    By solderingking in forum 2.x Help
    Replies: 0
    Last Post: Nov 22, 2012, 5:18 AM

Posting Permissions