Announcement

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

    How to override ListGrid's RecordClickHandler within ListGridField?

    Hello,

    I've been trying to resolve this problem for quite some time now, with no results.
    We've got a ListGrid with 5 fields. We've got a RecordClickHandler in the ListGrid which opens a new tab when a row is clicked.
    What we would want to do is exclude/override the handler in one column. That column is a custom made MyRemoveListGridField, which extends ListGridField, and has custom logic for record removal implemented with a RecordClickHandler.

    I read the documentation:
    HandlerRegistration addRecordClickHandler(RecordClickHandler handler)

    Executed when this field is clicked on. Note that if ListGrid.recordClick is also defined, it will be fired for fields that define a recordClick handler if the field-level handler returns true. Return false to prevent the grid-level handler from firing.
    ... but I can't really understand what the last sentence means. Where am I supposed to return false? Has someone got a working sample code?

    Using version: SC_SNAPSHOT-2011-05-05/EVAL

    Custom ListGridField constructor:
    Code:
    public MyRemoveListGridField(final ListGrid list, String name, String title, final String confirmQuestion,
    			final DSCallback callback) {
    	super(name);
    	setTitle(title);
    	setType(ListGridFieldType.ICON);
    	setWidth(16 + 6); // icon = 16x16
    	setCellIcon("/edoctoral/images/remove.png");
    
    	addRecordClickHandler(new RecordClickHandler() {
    		@Override
    		public void onRecordClick(final RecordClickEvent event) {
    			SC.confirm(Texts.get("removeQuestion"), confirmQuestion, new BooleanCallback() {
    				public void execute(Boolean value) {
    					if (Boolean.TRUE.equals(value)) {
    						if (callback != null) {
    							list.removeData(event.getRecord(), callback);
    						} else {
    							list.removeData(event.getRecord());
    						}
    					}
    				}
    			});
    		}
    	});
    }
    Code:
    ListGrid myList = new ListGrid();
    ListGridField id = new ListGridField("id");
    ListGridField oid = new ListGridField("oid");
    ListGridField type = new ListGridField("type");
    ListGridField name = new ListGridField("name");
    ListGridField remove = new MyRemoveListGridField(myList, "remove", "", Texts.get("confirmRemoveDocument"));
    
    myList.addRecordClickHandler(getRecordClickhandler()); // <-- this should be overriden in MyRemoveListGridField.
    
    myList.setFields(id, oid, type, name, remove);
    Thanks in advance.

    #2
    The docs should actually say call event.cancel() to prevent the other event firing, thanks for pointing this out.

    Comment


      #3
      Oh, alright. I'll see how that works out :>

      Comment


        #4
        Originally posted by Isomorphic
        The docs should actually say call event.cancel() to prevent the other event firing, thanks for pointing this out.
        It works. Thank you!

        Comment

        Working...
        X