Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ViewState fires changes at the initialization

    I tried to initialize a list grid with a view state I saved before. Problem is, the list grid immediately fires changed events (e.g. fieldStateChanged, viewStateChanged and groupStateChanged), which shouldn't happen, innit?

    The definition of the listgrid is currently this:
    Code:
    isc.ListGrid.create({
    	"fieldStateChanged" : function ()
    	{
    		console.log('Field state changed')
    	},
    	"groupStateChanged" : function () 
    	{
    		console.log('Group state changed')
    	},
    	"fields" :
    	[
    		{
    			"name" : "field"
    		}
    	],
    	"viewState" :
    	{
    		field :
    		[
    			{
    				name:"field",
    				width:80
    			}
    		]
    	},
    })
    Best Regards

    #2
    This is expected, or at least not considered a bug. If this creates an issue in your application, you can ignore this firing of the fieldStateChanged handlers by setting a flag right before you apply your viewState.

    Comment


      #3
      Ignoring these events seems like a dirty hack. I think these events shouldn't be fired at all, because the "change" is just initializing the list grid. You also don't fire events when e.g. setting the selected object initially. So why should these events fire?
      Could you implement a flag to choose, if initial changes should fire events or not?

      Best Regards

      Comment


        #4
        If you're interested in creation a framework flag that controls when these events fire, consider Feature Sponsorship.

        Comment


          #5
          Hi there, there is no need for a special flag, which surely would be an feature sponsorship. But the first calls of the methods viewStateChanged, fieldStateChanged and groupStateChanged are wrong. If you set the listgrid with an initial viewState there is no need to fire these events, because it was initiallly set. This methods should only be called after a modification on the fields, group etc.

          Is there a possibility to reach this without creating a counter or a flag in the listgrid? This doesn't seem to be a "nice" workaround.

          Best Regards

          Comment


            #6
            Sorry, we thought we were clear before: we do not consider this a bug, therefore the only remaining possibility would be a new feature. This is something you can pursue through feature Sponsorship if you think it's worthwhile, although obviously it's quite easy to avoid doing anything in response to the event firings that you'd prefer do not happen.

            Comment


              #7
              Ok, assuming the first call of viewStateChanged is not a bug, I'm wondering why after setting the field state the method fieldStateChanged is not also fired.

              While working in a workaround with the supposed solution, i stepped maybe into another bug.
              If you create a listgrid with a viewState and a field, the method "fieldStateChanged" is called. Thats the case, because viewState was changed for this field. But in this case the width of the field is not correctly set in the viewState of the ListGrid. Assuming the fieldState was changed and the event should be fired, the getViewState of the Listgrid should know the width of the field(s) at this time.

              The definition of the list grid:
              Code:
              isc.ListGrid.create({
              	"ID" : "listGrid",
              	"fieldStateChanged" : function () {
              		console.log(listGrid.getViewState())
              	},
              	"viewState" : "({field:[{name:\"aField\",width:170}]})",
              	"fields" :
              	[{
              			"name" : "aField"
              		}
              	],
              	"members" :
              	[],
              	"data" :
              	[]
              })
              The code which is returned to the console is in the box below. I think the width should be correctly set at this time
              Code:
              ({selected:null,field:[{name:"aField",width:null}],sort:{fieldName:null,sortDir:"ascending"},hilite:null,group:""})
              Best Regards

              Comment


                #8
                Please let us know what version and browser(s) you're seeing this with (please remember to always post this information).

                If you are not already using the latest patched version, please verify with the latest patched version.

                Finally, please clarify whether:

                1. you're seeing that there is only one fieldStateChanged notification and it lacks the width

                vs.

                2. you're seeing multiple fieldStateChanged notifications, where the final notification *does* have the width set, so this is just another complaint about notifications you'd prefer not to see.

                Comment


                  #9
                  Sorry, forgot about that.

                  I'm using latest versions of firefox, chrome and IE and SmartClient_v100p_2014-12-16_Pro.

                  When the list grid is created, the event "fieldStateChanged" only fires a single time and delivers the wrong view state.

                  Best regards

                  Comment


                    #10
                    We've made a change to address the issue of fieldStateChanged() firing - in fact, it was a manifestation of a logic bug in the processing of sortState - please retest with a build dated December 19 or later.

                    Comment


                      #11
                      Hi,
                      your fix works properly for the fieldStateChanged event, it no longer fires initializing a list grid with a given view state, thanks.

                      But there is still an issue with the events "groupStateChanged" and "viewStateChanged". These events still fire when initializing the list grid with a view state. The "groupStateChanged" event even fire if the view state doesn't include the group attribute.

                      Like the fieldStateChanged event, both named events shouldn't fire when initializing the list grid.

                      Following a small example of a list grid with set "groupStateChanged" event and an initial view state:
                      Code:
                      isc.ListGrid.create({
                      	"ID" : "listGrid",
                      	"groupStateChanged" : function () {
                      		console.log(listGrid.getViewState())
                      	},
                      	"width" : "100%",
                      	"height" : "100%",
                      	"viewState" : "({field:[{name:\"aField\",width:200}]})",
                      	"fields" :
                      	[{
                      			"name" : "aField"
                      		}
                      	],
                      	"members" :
                      	[],
                      	"data" :
                      	[]
                      })

                      Further I found an issue while working with datasources.
                      I was building a list grid with hidden list grid fields as well as a datasource. Herefor I saved a view state, where all of these hidden fields where visible. Afterwards I tried to set the saved view state, but the hidden fields stayed hidden, what they shouldn't.

                      I also tried the same scenario without a datasource and it worked properly.

                      Following a modified example of yours:
                      (http://smartclient.com/docs/10.0/a/s...taSourceFields)

                      fieldsDS.js
                      Code:
                      isc.ListGrid.create({
                      	ID : "countryList",
                      	width : 500,
                      	height : 224,
                      	alternateRecordStyles : true,
                      	dataSource : countryDS,
                      	autoFetchData : true,
                      countryDS
                      Code:
                      isc.DataSource.create({
                      	ID : "countryDS",
                      	fields : [{
                      			name : "countryName",
                      			title : "Country",
                      			"showIf" : function (list, field, fieldNum) {
                      				return false
                      			}
                      		}, {
                      			name : "countryCode",
                      			title : "Code"
                      		}, {
                      			name : "independence",
                      			title : "Independence",
                      			type : "date"
                      		}, {
                      			name : "population",
                      			title : "Population",
                      			type : "integer"
                      		}, {
                      			name : "gdp",
                      			title : "GDP ($B)",
                      			type : "float"
                      		}
                      	],
                      	clientOnly : true,
                      	testData : countryData
                      })
                      These issues occurred in the latest versions of Firefox, Chrome and IE as well as the latest build of smartclient (dec 19th).

                      Best Regards

                      Comment


                        #12
                        We actually made further changes earlier today that will deal with these other setStateXxx() methods being called (and their notifications fired) when they're not present in state.

                        Let us know if you still see issues with a build dated December 20 or later.

                        Comment


                          #13
                          The groupChanged event firing while initialization is also fixed now, thanks.

                          In my most recent post where some lines of code missing, sorry.

                          The problem when working with list grids which use datasources still exists.
                          In detail I built a list grid with a hidden field and a datasource. Afterwards I saved a view state, where the hidden field was visible. When trying to apply this view state to the list grid with the hidden field, it won’t show this field, but it shoud (it’s saved like that in the view state).

                          Following the complete example for reproduce the bug:
                          (http://smartclient.com/docs/10.0/a/s...taSourceFields)

                          fieldsDS.js:
                          Code:
                          isc.ListGrid.create({
                          	ID : "countryList",
                          	width : 500,
                          	height : 224,
                          	alternateRecordStyles : true,
                          	dataSource : countryDS,
                          	autoFetchData : true,
                          	viewState : "({selected:null,field:[{name:\"countryName\",width:null},{name:\"countryCode\",autoFitWidth:false,width:109},{name:\"independence\",width:80},{name:\"population\",width:null},{name:\"gdp\",width:null}],sort:{fieldName:null,sortDir:\"ascending\"},hilite:null})"
                          })
                          countryDS:
                          Code:
                          isc.DataSource.create({
                          	ID : "countryDS",
                          	fields : [{
                          			name : "countryName",
                          			title : "Country",
                          			"showIf" : function (list, field, fieldNum) {
                          				return false
                          			}
                          		}, {
                          			name : "countryCode",
                          			title : "Code"
                          		}, {
                          			name : "independence",
                          			title : "Independence",
                          			type : "date"
                          		}, {
                          			name : "population",
                          			title : "Population",
                          			type : "integer"
                          		}, {
                          			name : "gdp",
                          			title : "GDP ($B)",
                          			type : "float"
                          		}
                          	],
                          	clientOnly : true,
                          	testData : countryData
                          })
                          I tried the same with a list grid without datasource where it worked well.
                          I have also reproduced this issue locally with the version SmartClient_v100p_2015-01-13_Pro

                          Best Regards

                          Comment


                            #14
                            This is bad usage - there's no such property as DataSourceField.showIf.

                            If you were to set hidden:true instead on DataSourceField, that would be correct usage, but at that point viewState should not make the field visible in a grid (see docs for DataSourceField.hidden).

                            If you set ListGridField.hidden, the field appears as expected.

                            Comment


                              #15
                              Hey guys,

                              thanks, using ListGridFields works well.

                              I found another Issue while working with the “sortChanged” event.
                              In detail initializing a list grid with a view state will fire a sortChanged event. This always happens if the view state includes the “sort” keyword. It furthermore doesn’t matter if the sort expression is empty or includes e.g. a sort direction (empty in this case means the sort expression looks like follows: “sort” : {}).

                              Following a small example
                              Code:
                              isc.ListGrid.create({
                              	"ID" : "listGrid",
                              	"sortChanged" : function () {
                              		isc.say("Sort changed")
                              	},
                              	"fields" :
                              	[{
                              			"name" : "field"
                              		}
                              	],
                              	"viewState" : {
                              		sort : {
                              			fieldName : "field",
                              			sortSpecifiers : [{
                              					property : "field",
                              					direction : "ascending"
                              				}
                              			]
                              		}
                              	}
                              })
                              I also tried to set up the same list grid without using a view state. Herefor the “sortChanged” event also firest if a sortField is set.

                              The example without a view state
                              Code:
                              isc.ListGrid.create({
                              	"ID" : "listGrid",
                              	"sortChanged" : function () {
                              		isc.say("Sort changed")
                              	},
                              	"fields" :
                              	[{
                              			"name" : "field"
                              		}
                              	],
                              	"sortField" : "field"
                              })
                              This issue occurres in the latest nighly build of smartclient (Jan 26th 2015)
                              and happens in all current browsers (Firefox, Chrome and IE)

                              Best Regards

                              Comment

                              Working...
                              X