mahesh bhagirath
mahesh bhagirath

Reputation: 173

How do I select entire column on selecting row cell in NatTable?

We have a NatTable with no header and I treated the 1st row as a Header, - Register CELL_PAINTER to change the visualization to look this row similar to header.

   selectionLayer.registerCommandHandler(new CustomCommandHandler());
  public boolean doCommand(final ILayer layer, final ILayerCommand command)
          {
            if (command instanceof ViewportSelectRowCommand)
            {
               return ((ViewportSelectRowCommand) command).getRowPosition() <= 1;
            }
            else if (command instanceof SelectCellCommand)
            {
              return ((SelectCellCommand) command).getRowPosition() <= 1
            }
            return false;
          }

Now how can I select the entire column on selecting cells on 1st row. So that it should not affect the cell selection for other row cells.

Clicking any cells on 1st row should select entire column.

Clicking any cells on other rows should select the same cell. (currently this is happening)

Upvotes: 0

Views: 226

Answers (1)

Dirk Fauth
Dirk Fauth

Reputation: 4231

Although I am not quite sure what sense it makes to only have a body that is configured in a complicated way to look and behave like it has headers without really having headers (IMHO this does not make any sense), you need to register a custom handler that checks for the column position and transform the SelectCellCommand into a SelectColumnCommand.

this.selectionLayer.registerCommandHandler(new SelectCellCommandHandler(this.selectionLayer) {

    @Override
    public boolean doCommand(ILayer targetLayer, SelectCellCommand command) {
        if (command.convertToTargetLayer(targetLayer)
                && command.getColumnPosition() == 0) {
            return targetLayer.doCommand(
                    new SelectColumnCommand(
                            targetLayer,
                            command.getColumnPosition(),
                            command.getRowPosition(),
                            command.isShiftMask(),
                            command.isControlMask()));
        }
        return super.doCommand(targetLayer, command);
    }
});

But I expect there will be more issues on the way as the immitated headers do not behave like real headers also in other scenarios. You could also try to override getRegionLabelsByXY(int, int) but I am not sure if this would work or cause more problems.

Upvotes: 1

Related Questions