I ran into a similar problem. IMHO, the Grid component seems frustratingly half-finished. No default sort, no easy to modify sorting behaviors, etc.

You can't set the sortable property on the property model, since the data model is completely overwritten in Grid's setupDataModel method. You can't really modify the data model in any way via @SetupRender, @BeginRender or anything like that. One's changes are always lost, which is very annoying.

I ended up providing my own model to the grid and adding the column explicitly. My GridDataSource can handle the sorting on the virtual column. Generating the data model was very non-obvious (source is my GridDataSource.)

        @Inject
        private BeanModelSource modelSource;
        @Inject
        private ComponentResources componentResources;

        public BeanModel<?> newModel() {
                Class<?> rowType = source.getRowType();
                Messages containerMessages = componentResources.getMessages();
                return modelSource.createDisplayModel(rowType, 
containerMessages);
        }

Then I can modify the model:

    public BeanModel<?> getModel() {
        if (model == null) {
                model = newModel();
                PropertyModel p = model.add("type", null);
                p.sortable(true);
        }
        return model;
    }

You then list this new column, type in my case, in the t:include parameter for the grid (not in t:add!)

Norman Franke
Answering Service for Directors, Inc.
www.myasd.com



On Jan 26, 2010, at 2:55 PM, Howard Lewis Ship wrote:

That is the right approach, a smarter implementation of a property
within the BeanModel that can handle the sorting.

On Tue, Jan 26, 2010 at 11:00 AM, Michael Prescott
<michael.r.presc...@gmail.com> wrote:
How do you go about making a computed column in a Grid sortable? The docs on Grid are great, but in the example the computed column is non- sortable. Can I do it by providing a PropertyConduit through the grid's BeanModel
model?

Michael




--
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org


Reply via email to