9

Is it possible to make the entire row of a Wicket DataTable clickable ? if so, how ? I've seen examples of how to make a cell clickable by extending the PropertyColumn class, which is fairly easy but can't find an easy solution for the entire row.

1
  • I don't think there's an easier solution to this than using your own PropertyColumn implementation. You could have a look at newRowItem in the DataTable class and the the overridden method newRowItem in the DataGridView.
    – rotsch
    May 29, 2012 at 13:51

1 Answer 1

19

this do the work.

//override this method of the DataTable class
@Override
protected Item<T> newRowItem(String id, int index, final IModel<T> model) {

    Item<T> rowItem = new Item<T>(id, index, model);
    rowItem.add(new AjaxEventBehavior("onclick") {

        private static final long serialVersionUID = 6720512493017210281L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
        //callback or do some stuff
        }

    }); 
    return rowItem;

}
5
  • Very helpful answer. Additionally, overriding this method allows me set the markup id of each row, which his very helpful in my case as I have to trigger a jQuery event to highlight the newly inserted row which triggered a refresh of the DataTable. May 30, 2012 at 6:39
  • How do you know what object was clicked in the onEvent method?
    – DavidVdd
    Aug 23, 2012 at 8:25
  • by the model, internally wicket have a track of the relation between the rows and objects
    – osdamv
    Aug 23, 2012 at 17:03
  • Is there any way I can return a document on a row click? I get Ajax errors when I try to return a ResourceStreamRequestHandler (that contains a PDF I generate on the fly when you click the row).
    – Johncl
    Mar 31, 2014 at 10:54
  • @Johncl i think so, i would try to make my own ajaxbehaivor, however about a year i don't program in wicket :(
    – osdamv
    Apr 1, 2014 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.