making entire row of a wicket datatable clickable
Asked Answered
L

1

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.

Latticework answered 29/5, 2012 at 9:23 Comment(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.Dhruv
N
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;

}
Nicolette answered 29/5, 2012 at 19:46 Comment(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.Latticework
How do you know what object was clicked in the onEvent method?Linc
by the model, internally wicket have a track of the relation between the rows and objectsNicolette
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).Odessa
@Odessa i think so, i would try to make my own ajaxbehaivor, however about a year i don't program in wicket :(Nicolette

© 2022 - 2024 — McMap. All rights reserved.