Announcement

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

    EditorType events

    Hi All,

    I'm setting an Editor Type for a certain column in a list grid. The custom editor is defined (for illustration) like this:

    Code:
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.IconClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.IconClickHandler;
    
    public class TriggerField extends TextItem {
    
    	public TriggerField() {
    	
    	...
    	//Setup the icon here
    	...
    	addIconClickHandler(new IconClickHandler() {
    
    		public void onIconClick(IconClickEvent event) {
    		}
    	}
    
    	}
    
    }
    And is used like this:

    Code:
    ListGrid listGrid = new ListGrid();
    
    ListGridField newCol = new ListGridField("name", "Name");
    newCol.setEditorType(new TriggerField());
    ...
    So for that specific column, the editor for each record will be the TriggerField. So whenever the icon for the TriggerField is clicked, the onIconClick event handler will be invoked. But how do I know which record was clicked? I need to be able to have a different implementation for each record.

    I've been looking through the IconClickEvent object but I can't determine which record the editor was in.

    Any help/clues would be greatly appreciated....

    Kind Regards,
    Ben

    #2
    IconClick event has nothing to do with a grid so it doesn't contain that info. However in order to see the textitem with the icon, the user must have entered the editor. So having an addEditorEnterHandler() on your grid, which captures the current rowNum() in the event itself, can let you know that information if the user then clicks on the form icon while in the editor.

    Comment


      #3
      The idea is not a bad one, but I have 2 concerns:

      1 - There may be a possible event race between the addEditorEnterHandler and the onIconClick handlers. This could lead to unpredictable behavior.

      2 - If the setAlwaysShowEditors is set to true, will the addEditorEnterHandler event still be fired when expected?

      Nevertheless, I've managed to find a workaround:

      Code:
      public void onIconClick(IconClickEvent event) {
      
      int rowNum = event.getItem().getAttributeAsInt("rowNum");
      int colNum = event.getItem().getAttributeAsInt("colNum");
      With these values it's easy enough to calculate the actual column and record objects. If anyone has a better idea, please feel free to suggest it.

      Thank you,
      Ben

      Comment


        #4
        1 would not be a concern cause the editor would have to enter first even if the user immediately clicks the icon. 2 might be, I'd have to look into exactly how that works.

        Your idea I think is fine though as long as specifying those attributes beforehand isn't an issue. That takes care of the problem pretty easily.

        Comment

        Working...
        X