I am using Sencha's GXT 3.0 to render a ListViewCustomAppearance with a custom render defined through XTemplate (html/css). It works well when things are read only or when the interaction occurs on the list-level (ie. item select, item deselect).
How do I add mouse events to elements defined in the template's markup? My end goal is to have a clickable element inside an item in the list. The event handler would be in java.
Please let me know if this is going about it the wrong way..
ListViewCustomAppearance
is useful when you want to completely restructure the child dom, not just how each child gets drawn. By making one of these, you are taking over responsibility of deciding how to handle selection (see the com.sencha.gxt.widget.core.client.ListViewCustomAppearance.onSelect(XElement, boolean)
method).
This is important because ListView
already knows how to manage selection! You can set and configure a ListViewSelectionModel
on the ListView
itself to handle a variety of interactions, and can listen there for events.
Instead, consider just making a custom Cell
(probably starting from the AbstractCell
class) that renders your data how you want it to look. Override the render
method to specify how to append new content.
One more tip - the ListViewSelectionModel
idea may not work for you, depending on what kind of data you are trying to get about user interaction. Instead, consider also overriding the onBrowserEvent
method - this gives you the model object of the item that was modified, a reference to the root of the rendered content (from your render
method), and the event itself. Use the event object to see what happened (test the event.getType() against a string event type). When subclassing AbstractCell
, you also need to pass the event you are interested in to the superclass constructor.
Check out ActionCell
as a pretty good example of how to rough this out. It is designed to be abstract enough to be reusable, but that also tends to make it a poorer example.