Announcement

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

    datasource.updateData() unselects selected rows in listGrid

    1. v9.1p_2014-07-03/Pro"
    2. Any browser

    The selected row(s) in a databound listGrid get 'unselected' when the datasource has any record updated or added.

    This was not the case in earlier versions. Is this intended?

    Code below builds a datasource, listGrid and 2 buttons (load and update). Click the load button to load sample data, fetchData call back will select the 2nd row, then click the update button which will update the 2nd row in the datasource. This caused the selected row in the grid to be unselected.

    Code:
    public class Test implements EntryPoint {
    	ListGrid grid;
    	DataSource dataSource;
    
    	@Override
    	public void onModuleLoad() {
    		
    		VLayout appLayout = new VLayout();
    		appLayout.setWidth100();
    		appLayout.setHeight100();
    
    		buildDataSource();
    		buildGrid();
    		grid.setDataSource(dataSource, grid.getAllFields());
    		
    		IButton btnLoad = new IButton("Load");
    		btnLoad.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				loadData();					
    			}
    		});
    		
    		IButton btnUpdate = new IButton("Update");
    		btnUpdate.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				updateData();					
    			}
    		});
    		
    		appLayout.addMembers(btnLoad, btnUpdate, grid);
    		appLayout.draw();
    		
    	}
    	
    	protected void updateData() {
    		//update the 2nd record
    		Record rec = new Record();
    		rec = new ListGridRecord();
    		rec.setAttribute("fldId", 2);
    		rec.setAttribute("fld1", "val 222");
    		rec.setAttribute("fld2", 200);
    		rec.setAttribute("fld3", new Date());
    		
    		dataSource.updateData(rec);  //causes listgrid to unselect selected records
    		//v9.0p_2013-10-17 - works
    		//v9.1p_2014-07-03 - broken
    	}
    
    	private void loadData() {
    
    		ListGridRecord[] cacheData =  new ListGridRecord[3];
    		cacheData[0] = new ListGridRecord();
    		cacheData[0].setAttribute("fldId", 1);
    		cacheData[0].setAttribute("fld1", "val 1");
    		cacheData[0].setAttribute("fld2", 10);
    		cacheData[0].setAttribute("fld3", new Date());
    		cacheData[1] = new ListGridRecord();
    		cacheData[1].setAttribute("fldId", 2);
    		cacheData[1].setAttribute("fld1", "val 2");
    		cacheData[1].setAttribute("fld2", 20);
    		cacheData[1].setAttribute("fld3", new Date());
    		cacheData[2] = new ListGridRecord();
    		cacheData[2].setAttribute("fldId", 3);
    		cacheData[2].setAttribute("fld1", "val 3");
    		cacheData[2].setAttribute("fld2", 30);
    		cacheData[2].setAttribute("fld3", new Date());
    
    		dataSource.setCacheData(cacheData);
    		grid.setData(new ListGridRecord[] {});  //force the fetchData to execute it's callback
    		grid.fetchData(null, new DSCallback() {
    			
    			@Override
    			public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
    				//select the 2nd record
    				Record[] dataRecords = new Record[1];
    				dataRecords[0] = dsResponse.getDataAsRecordList().get(1); 
    				grid.selectRecords(dataRecords);
    			}
    		});
    
    	}
    
    	private void buildGrid() {
    		grid = new ListGrid();
    		grid.setAutoDraw(false);
    		grid.setShowAllRecords(true);
    		grid.setSelectionType(SelectionStyle.SINGLE);
    		grid.setCanSort(true);
    		grid.setUseAllDataSourceFields(false);
    		grid.setWidth100();
    		grid.setHeight100();
    		
    		ListGridField gfld1 = new ListGridField("fld1", "Field 1"); 
    		ListGridField gfld2 = new ListGridField("fld2", "Field 2");
    		ListGridField gfld3 = new ListGridField("fld3", "Field 3");
    
    		grid.setFields(gfld1, gfld2, gfld3);
    	}
    
    	private void buildDataSource() {
    		dataSource = new DataSource();
    		dataSource.setClientOnly(true);
    		dataSource.setDataFormat(DSDataFormat.JSON);
    		DataSourceField fldId = new DataSourceField("fldId", FieldType.INTEGER); fldId.setPrimaryKey(true);
    		DataSourceField fld1 = new DataSourceField("fld1", FieldType.TEXT);
    		DataSourceField fld2 = new DataSourceField("fld2", FieldType.INTEGER);
    		DataSourceField fld3 = new DataSourceField("fld3", FieldType.DATE);
    		dataSource.setFields(fldId, fld1, fld2, fld3);		
    	}
    
    }
    Thanks

    #2
    Any feedback?

    Comment


      #3
      Hi,

      As I recall I had this problem some time ago and I used some workarounds with this.
      Than it was corrected and now is back.
      I've just checked on SmartGWT 4.1p 2014-08-22.

      Below option has no effect:
      Code:
      listGrid.setReselectOnUpdate(true);
      Calling updateData() on ListGrid also deselects records.

      Regarding description this is a bug. :(

      Best regards
      Mariusz Goch

      Comment


        #4
        Thanks Mariusz.
        Isomorphic, any feedback?

        Comment


          #5
          [ListGrid] Selection bug

          Hi,

          I've found another thing and it definitely a bug.
          Reselection works only if any criteria were given. Not even related to data source fields.
          For example:
          Code:
          criteria = new Criteria();
          criteria.addCriteria("aaa", 5);
          And it doesn't matter if autoFetch is set to true or fetch is done by listGrid.fetch();
          With empty criteria selection disappears after update.

          Hope that helps.
          Best regards
          Mariusz Goch

          Comment


            #6
            This area was recently addressed, but it is possible we missed a case, or similar.
            We've assigned a developer to take a look. We'll follow up when we have more information.

            Regards
            Isomorphic Software

            Comment


              #7
              Please try the next nightly build (dated Aug 26 or above). The issue should now be resolved

              Regards
              Isomorphic Software

              Comment


                #8
                Thanks for the response and fix. I will test.

                Comment


                  #9
                  Hi,

                  Thanks for response.
                  I've just tested SmartGWT 4.1p 2014-08-28 and problem is solved.
                  Thank you.

                  Best regards
                  Mariusz Goch

                  Comment

                  Working...
                  X