javagwtuibindergwt2celltable

Dynamically update SelectionCell in CellTable in GWT


I am using gwt sdk 2.6.0 .

Please find my simplified problem statement below,

I have a CellTable containing Column as A and B . Col A contains non-editable value and Col B contains dropdown (SelectionCell) .

Col B dropdown options should be different in each row depending upon value of Col A .

I am able to render fixed value for dropdown options (i.e: same for all rows) but not dynamically different option as per my above description .

e.g: if Col A contains value as 'a' then , Col B will contain dropdown with options {x,y} and if Col A contains value as 'b' then , Col B will contain dropdown with options {y,z} ... which means set of values present in dropdown (in Col B) in each row changes depending on value of column A


Solution

  • You cannot show different options in each row using a SelectionCell. You will have to create your own custom cell that renders different options based on the object that is passed to it.

    UPDATE:

    You will need to extend the SelectionCell and

    (a) Add a method that sets the rules for including options in the dropdown list based on the information available to the cell. This can be either the current value (String) that is passed to this cell (e.g. if the value is "red" or "green" or "blue", show options "red, green, blue"), or a row number (e.g. for rows 1, 2 and 5 show options "red, green, blue"). Most likely, you will have to pass a reference to a data structure that you update elsewhere.

    (b) Override the render method to show options based on the rules set above.

    Alternatively, you can add methods for setting the options, and then call these methods when a cell in a different column is updated.