如何将 onclick 选择添加到 wicket TreeTable 的行?
我正在使用 TreeTable(来自 wicket-extensions),我希望能够通过单击行中的任意位置来选择行,而不是单击一个单元格中的链接来选择行的通常行为。我知道这应该可以通过向表示行的组件添加 AjaxEventBehavior("onclick") 来实现,但我似乎找不到公开行组件的任何方法。
I'm working with a TreeTable (from wicket-extensions) and I'd like to be able to select a row by clicking anywhere within it instead of the usual behavior of clicking the link in one cell to select the row. I understand this should be possible by adding an AjaxEventBehavior("onclick") to the component representing the row, but I can't seem to find any methods where the row component is exposed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我后来想出了一个解决办法。 row 元素可在
TreeTable
的populateTreeItem
方法中使用。当您创建树表时,请像这样重写此方法:通常在向行添加行为时有用。就我而言,我必须做更多的重写才能使这种单击切换行为与应该扩展/收缩节点的单击以及链接单击相协调。
在这些情况下,仅再次切换选择会产生不幸的效果,即短暂地将节点切换到不需要的状态,这是不理想的。相反,请重写
onJunctionLinkClicked
和onNodeLinkClicked
方法,这些方法将在点击事件到达我们刚刚设置的onClick
行为之前被触及在populateTreeItem
中:最后,添加方法
skipNextRowClick
和rowClickSelect
:I figured out a solution after. The row element is available in the
populateTreeItem
method fromTreeTable
. When you're creating your treetable, override this method like so:Generally useful in adding behaviors to rows. In my case, I'll have to do some more overriding to reconcile this toggle-on-click behavior with the clicks that are supposed to expand/contract nodes as well as link clicks.
Just toggling selection again in these cases has the unfortunate effect of briefly toggling the node in and out of the unwanted state, which is not ideal. Instead, override the
onJunctionLinkClicked
andonNodeLinkClicked
methods, which will be touched by a click event before it gets to theonClick
behavior we just set-up inpopulateTreeItem
:Finally, add the methods
skipNextRowClick
androwClickSelect
: