You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Thomerson <je...@wickettraining.com> on 2008/08/03 17:38:31 UTC

Hook for hiding columns of DataTable?

I've perused the source and can't find an easy way to do this.  I'm hoping
that maybe someone else has done it.

In an app for one customer, I have a table that lists parts that could be
purchased.  It is a subclass of DefaultDataTable.  I pass it in a custom
sortable data provider that wraps a list - so it has all parts in a list.
Then, I have filters above the table that can filter the list to a specific
category of parts.  But if you filter down to a certain category of parts,
some of those columns will be completely empty.  It would be nice to hide
them.  But the table was already created - and it operates off of a static
array of columns.  The column doesn't provide an isVisible mechanism.  Is
there an easy way to hide it, or does the table need to be recreated and
replaced within the ajax link?

The current code is basically like this:

final ListSortableDataProvider dp = new
ListSortableDataProvider(listOfParts, "columnToSortOn");
final PartInfoTable table = new PartInfoTable("table", new
VendorColumnFactory(vendor), vendor, dp);
add(table.setOutputMarkupId(true));

AjaxFallbackLink filterLink = new AjaxFallbackLink("link") {
    private static final long serialVersionUID = 1L;

    @Override
    public void onClick(AjaxRequestTarget target) {
        OrderVendorColumn column = (OrderVendorColumn)
nextFilterableColumn.getObject();
        String valueToFilterOn = (String) item.getModelObject();
        mPartFilter.addFilter(column, valueToFilterOn);
        dp.setList(mPartFilter.filterPartsList(parts));
        if (target != null) {
            target.addComponent(table);
            target.addComponent(LookupPartsPage.this.get("currentFilter"));
            target.addComponent(LookupPartsPage.this.get("addFilter"));
        }
    }
};
filterLink.add(new Label("label", item.getModel()).setRenderBodyOnly(true));


-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: Hook for hiding columns of DataTable?

Posted by Igor Vaynberg <ig...@gmail.com>.
this is on my list for 1.5, in 1.4/1.3 it would require too many api
breaks i think.

for now you can just replace the datatable with a new instance. the
only state you have to carry over is the current page, so its pretty
easy.

-igor

On Wed, Aug 6, 2008 at 9:45 AM, Ladislav Thon <la...@gmail.com> wrote:
> I've managed to "solve" similar problem by
>
> 1. setting a specific CSS class on each column, both in th and td tags (this
> can be done by overriding getCssClass() method of AbstractColumn)
>
> 2. setting a specific CSS class on the table when some columns should be
> hidden (this can be done e.g. using an AttributeAppender behavior)
>
> 3. hiding the columns in CSS, like table.hideFirstColumn .col1 {display:
> none}
>
> Not very nice (quite ugly in fact), but works for my needs. Yours might be
> more dynamic though (I basically have only two states, in the first all
> columns are shown, in the second few of them are hidden).
>
> LT
>
> 2008/8/3 Jeremy Thomerson <je...@wickettraining.com>
>
>> I've perused the source and can't find an easy way to do this.  I'm hoping
>> that maybe someone else has done it.
>>
>> In an app for one customer, I have a table that lists parts that could be
>> purchased.  It is a subclass of DefaultDataTable.  I pass it in a custom
>> sortable data provider that wraps a list - so it has all parts in a list.
>> Then, I have filters above the table that can filter the list to a specific
>> category of parts.  But if you filter down to a certain category of parts,
>> some of those columns will be completely empty.  It would be nice to hide
>> them.  But the table was already created - and it operates off of a static
>> array of columns.  The column doesn't provide an isVisible mechanism.  Is
>> there an easy way to hide it, or does the table need to be recreated and
>> replaced within the ajax link?
>>
>> The current code is basically like this:
>>
>> final ListSortableDataProvider dp = new
>> ListSortableDataProvider(listOfParts, "columnToSortOn");
>> final PartInfoTable table = new PartInfoTable("table", new
>> VendorColumnFactory(vendor), vendor, dp);
>> add(table.setOutputMarkupId(true));
>>
>> AjaxFallbackLink filterLink = new AjaxFallbackLink("link") {
>>    private static final long serialVersionUID = 1L;
>>
>>    @Override
>>    public void onClick(AjaxRequestTarget target) {
>>        OrderVendorColumn column = (OrderVendorColumn)
>> nextFilterableColumn.getObject();
>>        String valueToFilterOn = (String) item.getModelObject();
>>        mPartFilter.addFilter(column, valueToFilterOn);
>>        dp.setList(mPartFilter.filterPartsList(parts));
>>        if (target != null) {
>>            target.addComponent(table);
>>            target.addComponent(LookupPartsPage.this.get("currentFilter"));
>>            target.addComponent(LookupPartsPage.this.get("addFilter"));
>>        }
>>    }
>> };
>> filterLink.add(new Label("label",
>> item.getModel()).setRenderBodyOnly(true));
>>
>>
>> --
>> Jeremy Thomerson
>> http://www.wickettraining.com
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Hook for hiding columns of DataTable?

Posted by Ladislav Thon <la...@gmail.com>.
I've managed to "solve" similar problem by

1. setting a specific CSS class on each column, both in th and td tags (this
can be done by overriding getCssClass() method of AbstractColumn)

2. setting a specific CSS class on the table when some columns should be
hidden (this can be done e.g. using an AttributeAppender behavior)

3. hiding the columns in CSS, like table.hideFirstColumn .col1 {display:
none}

Not very nice (quite ugly in fact), but works for my needs. Yours might be
more dynamic though (I basically have only two states, in the first all
columns are shown, in the second few of them are hidden).

LT

2008/8/3 Jeremy Thomerson <je...@wickettraining.com>

> I've perused the source and can't find an easy way to do this.  I'm hoping
> that maybe someone else has done it.
>
> In an app for one customer, I have a table that lists parts that could be
> purchased.  It is a subclass of DefaultDataTable.  I pass it in a custom
> sortable data provider that wraps a list - so it has all parts in a list.
> Then, I have filters above the table that can filter the list to a specific
> category of parts.  But if you filter down to a certain category of parts,
> some of those columns will be completely empty.  It would be nice to hide
> them.  But the table was already created - and it operates off of a static
> array of columns.  The column doesn't provide an isVisible mechanism.  Is
> there an easy way to hide it, or does the table need to be recreated and
> replaced within the ajax link?
>
> The current code is basically like this:
>
> final ListSortableDataProvider dp = new
> ListSortableDataProvider(listOfParts, "columnToSortOn");
> final PartInfoTable table = new PartInfoTable("table", new
> VendorColumnFactory(vendor), vendor, dp);
> add(table.setOutputMarkupId(true));
>
> AjaxFallbackLink filterLink = new AjaxFallbackLink("link") {
>    private static final long serialVersionUID = 1L;
>
>    @Override
>    public void onClick(AjaxRequestTarget target) {
>        OrderVendorColumn column = (OrderVendorColumn)
> nextFilterableColumn.getObject();
>        String valueToFilterOn = (String) item.getModelObject();
>        mPartFilter.addFilter(column, valueToFilterOn);
>        dp.setList(mPartFilter.filterPartsList(parts));
>        if (target != null) {
>            target.addComponent(table);
>            target.addComponent(LookupPartsPage.this.get("currentFilter"));
>            target.addComponent(LookupPartsPage.this.get("addFilter"));
>        }
>    }
> };
> filterLink.add(new Label("label",
> item.getModel()).setRenderBodyOnly(true));
>
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>