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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Anthony Richir
  • 649
  • 2
  • 8
  • 31
  • 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 '12 at 13:51

1 Answers1

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;

}
osdamv
  • 3,493
  • 2
  • 21
  • 33
  • 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. – Anthony Richir May 30 '12 at 06:39
  • How do you know what object was clicked in the onEvent method? – DavidVdd Aug 23 '12 at 08:25
  • by the model, internally wicket have a track of the relation between the rows and objects – osdamv Aug 23 '12 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 '14 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 01 '14 at 15:38