1
votes

Im using a GWT Cell Table with sorting enabled on the columns. I am also providing an option of filtering the column. This is roughly how the header looks.

----ColumnName (Image) -------

When the user clicks on the image, i start off a filtering process. I achieved this using the Cell Table's addCellPreviewHandler. The issue I am facing is , when the image is clicked , the column sorts itself too. Can anyone tell me how to prevent this from happening ? To be clearer, I want the sort to be called when the user clicks anywhere in the header but the image.

Thanks.

  breakDownCellTable.addColumn(indexedColumn, columnHeader);
        final int currentColumnIndex = columnIndex;

        // Add a ColumnSortEvent.ListHandler to connect sorting to the
        // java.util.List.
        ListHandler<List<GwtContributorCellData>> columnSortHandler = new ListHandler<List<GwtContributorCellData>>(contributorList);
        columnSortHandler.setComparator(indexedColumn, new Comparator<List<CustomClass>>() {
            public int compare(List<CustomClass> o1, List<CustomClass> o2) {
                if (o1 == o2) {
                    return 0;
                }

                // Compare the columns.
                if (o1 != null) {
                    return (o2 != null) ? o1.get(currentColumnIndex).compareTo(o2.get(currentColumnIndex)) : 1;
                }
                return -1;
            }

        });

        breakDownCellTable.addColumnSortHandler(columnSortHandler);

and in the onBrowserEvent method:

if("click".equals(event.getType())){
            EventTarget eventTarget = event.getEventTarget();
            if(eventTarget.toString().contains("img") && !eventTarget.toString().contains("<th")){
                //event.stopPropagation();
              //  Window.alert("here");
                //breakDownCellTable.fireEvent()
                ColumnSortEvent.fire(breakDownCellTable, breakDownCellTable.getColumnSortList());
1
The event object in the event handler may have an event.stopPropagation() method to prevent the handlers in the superclass from picking it up. If not, the CellTable has a default implementation of ColumnSortEvent.Handler that you can probably override - Churro

1 Answers

0
votes

Your can implement a subclass of the cell you're using and override the onBrowserEvent() method.

This post explains how to find out which DOM element is the exact source of the event.

Once you know that the image has been clicked or not, fire the filtering / sorting event accordingly.