Announcement

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

    Executing code on ListGrid boolean toggle - WITHOUT edit

    It seems that, on a ListGrid, with autoSaveEdit:false, whose ListGridFields have canEdit:true, canToggle:true, the changed/change callbacks do not get called when the user toggles a boolean value (i.e. without going into edit mode).

    This strikes me as odd, because surely the value *has* changed even though you haven't double clicked and gone into edit mode?

    This matters in this case because when a boolean is set in one column, we must set the boolean in a different column to the opposite value. We can't find *anything* which gets triggered when simply "toggling" a boolean select (and we've wasted a man day on this so far).

    One solution in this case might have been to use formatCellValue to return html radio inputs with matched IDs (which I have tried and it works) but of course, the form then doesn't pick up any changed values in input.

    Totally stuck... please advise... so far SmartClient has amazed by coming up with the right solutions everytime, IF you know where to look. Will this be the case again?

    #2
    I should probably mention, the closest we've gotten is :

    editEvent:"click" on the main Grid (which is a pain, as it applies to all the regular text fields as well), with changed:function(...){...} on the relevant fields.

    The problem with this is e.g.

    A boolean field is selected (true). You click on it - and you are immediately both in edit mode and the field has become unselected (false) but the change callback handler for the field is NOT called. The callback handler is ONLY called on subsequent clicks while you're still in edit mode!

    Comment


      #3
      Another follow up for anybody with similar issues :

      If you then also remove canToggle:true on a ListGridField, but still have editEvent:"click" on the Grid, the first click will set it into edit mode, so with a second click you can then change the boolean value, causing the ListGridField's "changed" callback to fire, so you can update associated fields as required.

      It still doesn't solve the basic requirement which is for boolean ListGridFields to change their state with a single click, and for us to know this has happened so that we can execute further code to update the state of other values/columns/fields.

      Comment


        #4
        Please show sample code that reproduces the problem if added to a specific sample from the Showcase.

        Comment


          #5
          Here's some test code. Please put a "tick.png"/"cross.png" into your images folder.

          Note :
          1) Single clicking on the "Sel" boolean fields changes the state of the field BUT the "changed" callback does not fire.

          2) Double clicking to edit the field, causes the original style checkbox to reappear (I have tried setting the keys in editorValueIcons to "selected/checked" etc.) and then not disappear again - but then the "changed" callback IS fired.

          What I really need - and would expect - is for the edit mode to be deactivated (e.g. with editEvent="none") BUT for the changed/change callback to fire when the state is toggled... so that I can respond and do useful things with that knowledge.

          Thanks.

          Code:
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
                  <SCRIPT>
                      var isomorphicDir = "./lib/isomorphic/";
                  </SCRIPT>
                  <script src="./lib/isomorphic/system/modules/ISC_Core.js">
                  </script>
                  <SCRIPT SRC=./lib/isomorphic/system/modules/ISC_Foundation.js>
                  </SCRIPT>
                  <SCRIPT SRC=./lib/isomorphic/system/modules/ISC_Containers.js>
                  </SCRIPT>
                  <SCRIPT SRC=./lib/isomorphic/system/modules/ISC_Grids.js>
                  </SCRIPT>
                  <SCRIPT SRC=./lib/isomorphic/system/modules/ISC_Forms.js>
                  </SCRIPT>
                  <SCRIPT SRC=./lib/isomorphic/system/modules/ISC_DataBinding.js>
                  </SCRIPT>
                  <SCRIPT SRC=./lib/isomorphic/skins/SmartClient/load_skin.js>
                  </SCRIPT>	
              </head>
              <body>
                  <script language="javascript">
                  	var testData = [{"Foo":"FooEntry1","Sel":true},{"Foo":"FooEntry2","Sel":true},{"Foo":"FooEntry3","Sel":true}];
          
          			
                  	isc.ListGrid.create({
                          ID: "Grid_1",
                          title: "Test",
                          width: 500,
                          height: 250,
                          selectionType: "single",
          				showAllRows:false,
          				dataPageSize:20,
          				dataFetchMode: "paged",
          				autoSaveEdits : false,
          				autoFetchData: true,
          				fields : [
          					{name:"Foo",title:"Fooo",type:"text",},
          					{
          						name:"Sel",
          						title:"Selection",
          						type:"boolean",
          						canEdit:true,
          						canToggle:true,
          						valueIcons : {
          							"true" : "tick.png",
          							"false" : "cross.png"						
          						},
          						editorValueIcons : {
          							"true" : "tick.png",
          							"false" : "cross.png"						
          						},
          						changed:function(){alert('I have changed')},
          						showValueIconOnly:true,
          					}],
                          data:testData
                      });
                  </script>
          	</body>
          </html>

          Comment


            #6
            The reason the change / changed handlers were not firing is that these are passed onto the edit items that are auto created for the row -- but in the 'canToggle:true' case, there are no edit items created so these methods never fired.
            We've now made a change to directly fire listGridField.change and listGridField.changed if canToggle is true for a field and the user toggles the value which should give you the behavior you need. Note that the "form" and "item" parameters will be null in this case (as no edit item will have been created for the field being toggled).

            You should see this change show up in our next nightly build.

            If you need an immediate workaround, another option would be to override setEditValue() for your grid -- this method is fired by the canToggle behavior so you can catch the case where the user toggles a field value.

            Comment


              #7
              That is brilliant. I am just becoming more and more deeply impressed with SmartClient every day. After our evaluation the client has moved the UI team over to SC and so far it has delivered a huge boost (as much because we create a custom JS class per view page, meaning that server side MVC developers only need to know the class name, the contents of the configuration object, and from that point on both teams can work entirely independently).

              Incidently, we found a way around the problem which looked something like this early version :

              Code:
              formatCellValue:function (value,record,rowNum,colNum,grid)
              						{	
              							var recordID = grid.getRecordIndex(record);
              							if (value==true){								
              							 return '<div onclick="'+grid.ID+'.setEditValue('+rowNum+','+colNum+',false);'+grid.ID+'.setEditValue('+rowNum+','+(colNum - 1)+',true);"><input type="radio" checked="checked"/></div>';
              							} else {
              							 return '<div onclick="'+grid.ID+'.setEditValue('+rowNum+','+colNum+',true);'+grid.ID+'.setEditValue('+rowNum+','+(colNum - 1)+',false);"><input type="radio"/></div>';
              							}
              						},

              Comment

              Working...
              X