Search code examples
vaadinvaadin7

Responding to clicking a specific column of a Vaadin table row


I am new to Vaadin. I have three different views. View1 has a table with column1,column2. For a particular table row,when i click on column1,i want to navigate to view2 and when i click on column2 i want to be able to navigate to view3. I can respond to the row click as a whole using the ValueChanged event.But how do i handle click on the specific column of the row? The way i am handling the row-click is as follows

summaryTable.addValueChangeListener(new Property.ValueChangeListener() {
    @Override
    public void valueChange(Property.ValueChangeEvent event) {
        String provider = summaryTable.getContainerProperty(summaryTable.getValue(), "provider").toString();
        UI.getCurrent().getNavigator().navigateTo(ViewsEnum.PROVIDERS.viewName()+"/"+provider);
    }
});

Please help


Solution

  • The logic in the below code gave me the column i clicked on. I am using the value of selectedColumn in valueChange() to determine which View i want to navigate to.

    summaryTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(ItemClickEvent event) {
            // TODO Auto-generated method stub
            selectedColumn = (String)event.getPropertyId();
        }
    });
    

    Not sure if that's the right way to do it or is just a hack. I am sure there is a better way around.Please sugggest!