Announcement

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

    ListGrid: Ungrouping causes selection to disappear

    Hi,

    I have some selected records in a grouped ListGrid. When clicking Ungroup in the header, the selection is gone.

    In the target application, I only have a checkbox style, and not a "record row selected" style. In my application, the checkboxes remain checked, while the underlying call to getSelectedRecords() does not return them.
    This does not happen in the following standalone repro case. I assume it's because we are tinkering with redraw behavior. But if the following is a bug and is fixed, this won't be a problem for my application anymore.


    Repro:
    * click 'add data'
    * open group 1 to verify something is selected
    * click 'check selection'
    OK, selected record info is shown
    * in the grid header, column a, click "ungroup"
    <= all selected rows are gone
    * click 'check selection'
    NOK, no more selected records
    Code:
    final HTMLFlow infoPane = new HTMLFlow("Selection?");
    
    final String GROUP_FIELD = "_group";
    final String SELECTED_FIELD = "_selected";
    
    final ListGrid grid = new ListGrid();
    grid.setSelectionProperty(SELECTED_FIELD);
    grid.setGroupByField(GROUP_FIELD);
    grid.setGroupStartOpen(GroupStartOpen.NONE);
    grid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
    grid.setSelectionType(SelectionStyle.SIMPLE);
    
    ListGridField field1 = new ListGridField("a");
    ListGridField field2 = new ListGridField("b");
    ListGridField field3 = new ListGridField(GROUP_FIELD);
    grid.setFields(field1, field2, field3);
    
    Button addData = new Button("Add data to grid");
    addData.addClickHandler(new ClickHandler() {
    
    	public void onClick(ClickEvent event) {
    		ListGridRecord [] data = new ListGridRecord[20];
    		for (int i=0; i<data.length; i++) {
    			data[i] = new ListGridRecord();
    			data[i].setAttribute("a", i);
    			data[i].setAttribute("b", "this is b " + i);
    			
    			data[i].setAttribute(SELECTED_FIELD, i%3 != 0);
    			data[i].setAttribute(GROUP_FIELD, i%3);
    		}
    		grid.setData(data);
    		
    		
    		
    	}
    });
    
    Button checkSelection = new Button("Check Selection");
    checkSelection.addClickHandler(new ClickHandler() {
    	
    	public void onClick(ClickEvent event) {
    		StringBuilder info = new StringBuilder();
    		ListGridRecord [] records = grid.getSelectedRecords();
    		for (ListGridRecord r : records) {
    			info.append(r.getAttribute("a"));
    			info.append("<br/>");
    		}
    		infoPane.setContents(info.toString());
    	}
    });
    
    
    VLayout layout = new VLayout();
    layout.setMembers(grid, addData, checkSelection, infoPane);
    Build v8.3p_2012-11-30/Pro Deployment (built 2012-11-30)

    #2
    You can work around this by specifying a DataSource for the listGrid with a primaryKey field set (which would be expected to be unique per record, of course).

    Let us know if that won't work for your application

    Thanks
    Isomorphic Software

    Comment


      #3
      In the end app, that should be the case, indirectly:
      the listgrid does not have a direct DataSource, it is bound to a ValuesManager at path "/objectA". The ValuesManager DataSource has some fields. Field "objectA" of that DataSource is of type of DataSource and this one has the PK field defined on it.

      I will try adding that same PK field in the ListGridFields of the ListGrid to test (and then make it hidden in the end if works).

      Comment


        #4
        I will try adding that same PK field in the ListGridFields of the ListGrid
        Too bad, that didn't work. Do you have any other ideas?

        Comment


          #5
          I think what you're saying is that you have 2 nested dataSources. For the same of argument - "dataSource1", which has a field "objectA", of type "dataSource2", then the valuesManager is bound to dataSource1, and the list grid is showing entries from field "objectA", which are of type "dataSource2".

          If so, presumably you can just set the dataSource on the grid to be "dataSource2" as well (and set "saveLocally" to true to ensure the grid doesn't attempt to actually save edits directly against its dataSource, if it is editable).

          Let us know if this won't work for you.

          Comment


            #6
            I have added a flag to ignore the onSelectionChanged Event on that grid onGroupBy in my handling code.

            With (and I noticed also without) setting the DataSource on the grid to that nested DS this fixes the use case. Which is fine for me now :)

            Comment

            Working...
            X