Announcement

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

    ListGrid + checkbox

    Hello everyone.

    I'm currently migrating from gwt-ext to smartgwt that looks great and responds to lot of my requirements.

    I currently a problem with check boxes inside listgrids.

    I would like an CellChangedEvent to be fired when the user changes the value. I don't want the user to have to enter edit mode, change the value then exit the edit mode so the event can be fired. It's against UI best practice. Currently i have not manage to get this behavior.

    I tried lot of combination between setEditEvent (CLICK or Not), ListGridField.setCanToggle, ListGrid.CanEdit, etc.

    The behavior I'm looking for is "when i click on a checkbox, whether or not the row is selected, the event is just fired (onCellChanged would be fine)".

    Or maybe i'm missing something?


    Some of my code :

    Code:
    ListGrid declaration :
    
    		setSelectionType(SelectionStyle.SINGLE);
    		setAlternateRecordStyles(true); 
    		setAutoFetchData(true);
    		setShowAllRecords(true);  
    		setCanHover(false);
    		setCanReorderFields(false);
    		setCanEdit(true);
    		setHeaderBarStyle("headerCell");
    		setShowHeaderMenuButton(false);
    		setShowHeaderContextMenu(false);
    		setWrapCells(false);
    		setEditOnFocus(true);
    		setEditEvent(ListGridEditEvent.CLICK);  
    		setEditByCell(true);
    		setFields(getTableFields());
    
    private ListGridField[] getTableFields() {
    		ArrayList<SheetColumnDescriptorVO> columnDescriptors = sheetVO.getColumnDescriptors();
    		ListGridField[] fields = new ListGridField[columnDescriptors.size()];
    		for (int i = 0; i < columnDescriptors.size(); i++)
    			fields[i] = getTableField(columnDescriptors.get(i));
    		return fields;
    	}
    
    private ListGridField getTableField(SheetColumnDescriptorVO descriptor) {
    		ListGridField field = new ListGridField(descriptor.getId(), descriptor.getName() != null  && !descriptor.getName().trim().equals("") ? descriptor.getName() : "_");
    		
    		field.setAlign(Alignment.LEFT);
    		field.setCanFilter(false);
    		field.setCanGroupBy(false);
    		field.setCanSort(false);
    		field.setCanEdit(descriptor.isEditable());
    
    		switch (desc.getType()){
    [....]
    		case : Util.TYPE_BOOLEAN {
    				field.setType(ListGridFieldType.BOOLEAN);
    				field.setAlign(Alignment.CENTER);
    				field.setCanToggle(true);
    				break;
    		}
    [....]
    
    		return field;
    }

    #2
    This is what setCanToggle(true) is for, but keep in mind, CellChanged only after a successful save. If you have saveByCell:false (the default), no CellChanged event will fire until you leave the row. There is a more frequent field.changed() event in SmartClient but it hasn't been exposed yet in SmartGWT (coming soon).

    Comment


      #3
      ListGrid's cellChanged event has been renamed to cellSaved to correctly represent its functionality.

      I've also added ListGridField.addCellChangeHandler and ListGridField.addCellChangedHandler in SVN. You'll want to use these to detect cell value changes.

      Sanjiv

      Comment


        #4
        Yeah!

        Thanks for your prompt replies. It helps a lot.

        Now, i'm able to get the event, thanks to your update Sjivan. One problem remain since i still have to click on the cell once before any event to be fired.

        To understand:

        I have a row with 2 columns. The first is a checkbox, the second is a simple label.

        When i click on the row but not directly on the checkbox cell, the row is selected. If now, i want to change the value of the checkbox, i have to click at least twice on the checkbox cell. The first click visually toggles the checkbox with no event fired ; the second (and the next ones) toggles the checkbox and fires the events. Do you get it?

        And i have a remark about the added handlers (ListGridField.addCellChangeHandler and ListGridField.addCellChangedHandler).

        CellChangedEvent has no getOldValue(), just getValue()

        And CellChangeEvent has both. But maybe that one should not have an oldValue since the value has not changed yet.

        This is maybe not consistent with CellSavedEvent which has getOldValue() and getNewValue().

        Thank you both of you for your help (i also added saveByCell:true)

        Comment


          #5
          fyi I renamed ListGridField.addCellChangeHandler / ListGridField.addCellChangedHandler to ListGridField.addChangeHandler / ListGridField.addChangedHandler to be consistent with the SC API's.

          I an able to reproduce the click behavior you mention. Looking into it. Feel free to create an issue for it.

          Sanjiv

          Comment


            #6
            Howdy, apologies for the late bump, but I'm experiencing this problem with having a checkbox field in a listgrid and wondering if there was a fix to come.

            Code:
            allocateField.setType(ListGridFieldType.BOOLEAN);
            allocateField.setCanToggle(true);
            allocateField.setCanEdit(true);
            grid.setEditEvent(ListGridEditEvent.CLICK);
            
            allocateField.addRecordClickHandler(new RecordClickHandler() {			
            	@Override
            	public void onRecordClick(RecordClickEvent event) {
            		System.out.println("clicked");
            	}
            });
            allocateField.addChangedHandler(new com.smartgwt.client.widgets.grid.events.ChangedHandler() {			
            	@Override
            	public void onChanged(com.smartgwt.client.widgets.grid.events.ChangedEvent event) {
            		System.out.println("changed");
            	}
            });
            allocateField.addChangeHandler(new ChangeHandler() {			
            	@Override
            	public void onChange(ChangeEvent event) {
            		System.out.println("change");
            	}
            });
            Consistent with the descriptions above, the change/changed events aren't firing until I've clicked on the checkbox once (also the click event only fires the first time and doesn't fire afterwards). This is using GWT 2.0 in FF 3.5.7 and SmartGWT 2.0 nightly 934.

            Comment

            Working...
            X