I need to add Anchor with clickHandler to ListGridRecord. Click to Anchor should call the function (adding more rows to ListGrid). I'm able to write Anchor with href:
private void addAnchorToRecord(ListGridRecord rec) {
String img = "<img src='pict/Plus.png'/>";
Anchor myAnchor = new Anchor(img, true, "example.html");
String value = myAnchor.toString();
rec.setAttribute("versions", value);
}
But this code:
private void addAnchorToRecord(final ListGridRecord rec) {
String img = "<img src='pict/Plus.png'/>";
Anchor myAnchor = new Anchor(img, true);
myAnchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addExtraRows(rec);
}
});
String value = myAnchor.toString();
rec.setAttribute("versions", value);
}
doesn't work. I see image, but after click nothing happens. In second case
value = "<a href="javascript:;" class="gwt-Anchor"><img src="pict/Plus.png"></a>"
I think in this place i lose information about clickHandler. How can I succesful add ClickHandler in this situation?
EDIT
I used LinkItem:
private void updateVersions(final ListGridRecord rec) {
LinkItem linkItem = new LinkItem("link");
linkItem.setTitle("LinkItem");
linkItem.setLinkTitle("Click Me");
linkItem.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
showPreviousVersions(rec);
}
});
rec.setAttribute("versions", linkItem);
}
Then in my cell was only "[object Object]"
Functionality I need: set attribute to ListGridRecord, which has icon and clickHandler.
Its easier if you just add a button in the ListGridRecord and then add a clickhandler to the button. It must be done like this:
When configuring the ListGrid:
setShowRecordComponents (true );
setShowRecordComponentsByCell(true );
When setting fields
...
ListGridField btnField= new ListGridField("btnFieldName", " ");
...
And then just override createRecordComponent like this:
@Override
protected Canvas createRecordComponent(final ListGridRecord record, final Integer colNum){
if(getFieldName(colNum).equalsIgnoreCase(("btnFieldName"))){
IButton btn= new IButton("");
//configure the button
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
//your logic
}
});
return btn;
}
return super.createRecordComponent(record, colNum);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.