You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by sv...@madsep.de on 2009/12/10 00:56:27 UTC

Changing tables background-color depending on a value

Hi list,

I'd like to change the background-color of a table row depending on a value that
is displayed in the table.
I am showing a table with one row for each day in the current month, to
highlight weekends saturdays and sundays should have a different
background-color.

Usually I am using Decorator for handling value-objects, but I don't see a way
how to change the background-color of the table-cells.

Is there a way to do this?

Thanks in advance
SVen


Re: Changing tables background-color depending on a value

Posted by "Adrian A." <a....@gmail.com>.
Or you could use jQuery to do the job in the browser only: if the 
coloring criteria can be deduced purely from the values. E.g.:

http://www.exforsys.com/tutorials/jquery/jquery-three-color-alternating-pattern.html

e.g. in the text from the above URL, in the second code sample, at:
  "//Code to be applied to each element in the matched set. "
you can put your own JavaScript code that checks if those values are 
met, and than apply color only to those rows:
----------------------
$(this).addClass('myColorForThoseValues');
----------------------

and of course, you need to define in your CSS the
".myColorForThoseValues" class.

Adrian.

> Or a custom Column. At least the method Column#renderTableData would 
> have to be adapted to add attributes on a per cell basis.
> 
> kind regards
> 
> bob
> 
> 
> Malcolm Edgar wrote:
>> Hi Sven,
>>
>> You will probably need to subclass table to do this.
>>
>> regards Malcolm Edgar
>>
>> On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
>>> Hi list,
>>>
>>> I'd like to change the background-color of a table row depending on a 
>>> value that
>>> is displayed in the table.
>>> I am showing a table with one row for each day in the current month, to
>>> highlight weekends saturdays and sundays should have a different
>>> background-color.
>>>
>>> Usually I am using Decorator for handling value-objects, but I don't 
>>> see a way
>>> how to change the background-color of the table-cells.
>>>
>>> Is there a way to do this?
>>>
>>> Thanks in advance
>>> SVen
>>>
>>>
>>
> 
> 


Re: Changing tables background-color depending on a value

Posted by Bob Schellink <sa...@gmail.com>.
Hi Sven,

Lets try and incorporate this feature in the next release, 2.2.0. Can you open a JIRA and add your 
implementation to the issue?

kind regards

bob

On 3/02/2010 09:00 AM, sven.pfeiffer@madsep.de wrote:
> Hi guys,
>
> I'd like to restart the discussion whether it should be possible to be
> able to
> change column attributes from within a Decorator.
>
> I've been playing around with jQuery a lot, lately and I think it would
> be great
> if I could set a columns class from java inside a decorator, based on it's
> value, or some other (not displayed) value of the object.
>
> Of course these changes shouldn't change the signature, which would break
> existing code, but I think my draft (ColumnDecorator) would be a good
> solution.
>
> kind regards
> SVen
>
> Zitat von Sven Pfeiffer <sv...@madsep.de>:
>
>> I've been thinking about this too.
>>
>> A possible solution, that won't have any impact on existing apps,
>> would be to create an abstract class (ColumnDecorator) like this.
>>
>> public abstract class ColumnDecorator implements Decorator {
>>
>> private Column column;
>>
>> public Column getColumn() {
>> return column;
>> }
>>
>> public void setColumn(Column column) {
>> this.column = column;
>> }
>>
>> public abstract String render(Object object, Context context);
>>
>> }
>>
>> Then you could check if the Column has a ColumnDecorator set and call
>> the setter.
>>
>> Bob Schellink wrote:
>>> I think it might be a problem if we change the signature of Decorator
>>> as it will break existing applications and Decorator is used by Tree
>>> and PropertySelect as well.
>>>
>>> Will have to think a bit how we can introduce attribute manipulation
>>> at the cell level without impacting existing apps.
>>>
>>> kind regards
>>>
>>> bob
>>>
>>> sven.pfeiffer@madsep.de wrote:
>>>> I am wondering if it would be nice if the decorator has the
>>>> capability to change the column style.
>>>>
>>>> I guess it would be quite easy if
>>>>
>>>> a) the decorator would have a reference to the Column
>>>> b) the content, which is rendered by the decorator, must be
>>>> processed before the
>>>> Column itself is rendered (rendering = adding it to the
>>>> HtmlStringBuffer), this
>>>> could be done if renderTableDataContent is called at the beginning of
>>>> renderTableData, storing the result of renderTableDataContent in a
>>>> String
>>>> before putting it to the buffer
>>>>
>>>> If you think this is a good idea I could create a patch and open a
>>>> jira-issue
>>>> for the change.
>>>>
>>>> Zitat von Bob Schellink <sa...@gmail.com>:
>>>>
>>>>> Or a custom Column. At least the method Column#renderTableData
>>>>> would have to be adapted to add attributes on a per cell basis.
>>>>>
>>>>> kind regards
>>>>>
>>>>> bob
>>>>>
>>>>>
>>>>> Malcolm Edgar wrote:
>>>>>> Hi Sven,to subclass table to do this.
>>>>>>
>>>>>> regards Malcol
>>>>>>
>>>>>> You will probably need m Edgar
>>>>>>
>>>>>> On Thu, Dec 10, 2009 at 10:56 AM, <sv...@madsep.de> wrote:
>>>>>>> Hi list,
>>>>>>>
>>>>>>> I'd like to change the background-color of a table row depending
>>>>>>> on a value that
>>>>>>> is displayed in the table.
>>>>>>> I am showing a table with one row for each day in the current
>>>>>>> month, to
>>>>>>> highlight weekends saturdays and sundays should have a different
>>>>>>> background-color.
>>>>>>>
>>>>>>> Usually I am using Decorator for handling value-objects, but I
>>>>>>> don't see a way
>>>>>>> how to change the background-color of the table-cells.
>>>>>>>
>>>>>>> Is there a way to do this?
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>> SVen
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>
>
>


Re: Changing tables background-color depending on a value

Posted by sv...@madsep.de.
Hi guys,

I'd like to restart the discussion whether it should be possible to be able to
change column attributes from within a Decorator.

I've been playing around with jQuery a lot, lately and I think it would 
be great
if I could set a columns class from java inside a decorator, based on it's
value, or some other (not displayed) value of the object.

Of course these changes shouldn't change the signature, which would break
existing code, but I think my draft (ColumnDecorator) would be a good 
solution.

kind regards
SVen

Zitat von Sven Pfeiffer <sv...@madsep.de>:

> I've been thinking about this too.
>
> A possible solution, that won't have any impact on existing apps, 
> would be to create an abstract class (ColumnDecorator) like this.
>
> public abstract class ColumnDecorator implements Decorator {
>
>    private Column column;
>
>    public Column getColumn() {
>        return column;
>    }
>
>    public void setColumn(Column column) {
>        this.column = column;
>    }
>
>    public abstract String render(Object object, Context context);
>
> }
>
> Then you could check if the Column has a ColumnDecorator set and call 
> the setter.
>
> Bob Schellink wrote:
>> I think it might be a problem if we change the signature of 
>> Decorator as it will break existing applications and Decorator is 
>> used by Tree and PropertySelect as well.
>>
>> Will have to think a bit how we can introduce attribute manipulation 
>> at the cell level without impacting existing apps.
>>
>> kind regards
>>
>> bob
>>
>> sven.pfeiffer@madsep.de wrote:
>>> I am wondering if it would be nice if the decorator has the
>>> capability to change the column style.
>>>
>>> I guess it would be quite easy if
>>>
>>> a) the decorator would have a reference to the Column
>>> b) the content, which is rendered by the decorator, must be 
>>> processed before the
>>> Column itself is rendered (rendering = adding it to the 
>>> HtmlStringBuffer), this
>>> could be done if renderTableDataContent is called at the beginning of
>>> renderTableData, storing the result of renderTableDataContent in a String
>>> before putting it to the buffer
>>>
>>> If you think this is a good idea I could create a patch and open a 
>>> jira-issue
>>> for the change.
>>>
>>> Zitat von Bob Schellink <sa...@gmail.com>:
>>>
>>>> Or a custom Column. At least the method Column#renderTableData 
>>>> would have to be adapted to add attributes on a per cell basis.
>>>>
>>>> kind regards
>>>>
>>>> bob
>>>>
>>>>
>>>> Malcolm Edgar wrote:
>>>>> Hi Sven,to subclass table to do this.
>>>>>
>>>>> regards Malcol
>>>>>
>>>>> You will probably need m Edgar
>>>>>
>>>>> On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
>>>>>> Hi list,
>>>>>>
>>>>>> I'd like to change the background-color of a table row depending 
>>>>>> on a value that
>>>>>> is displayed in the table.
>>>>>> I am showing a table with one row for each day in the current month, to
>>>>>> highlight weekends saturdays and sundays should have a different
>>>>>> background-color.
>>>>>>
>>>>>> Usually I am using Decorator for handling value-objects, but I 
>>>>>> don't see a way
>>>>>> how to change the background-color of the table-cells.
>>>>>>
>>>>>> Is there a way to do this?
>>>>>>
>>>>>> Thanks in advance
>>>>>> SVen
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>




Re: Changing tables background-color depending on a value

Posted by Sven Pfeiffer <sv...@madsep.de>.
I've been thinking about this too.

A possible solution, that won't have any impact on existing apps, would 
be to create an abstract class (ColumnDecorator) like this.

public abstract class ColumnDecorator implements Decorator {

    private Column column;

    public Column getColumn() {
        return column;
    }

    public void setColumn(Column column) {
        this.column = column;
    }

    public abstract String render(Object object, Context context);

}

Then you could check if the Column has a ColumnDecorator set and call 
the setter.

Bob Schellink wrote:
> I think it might be a problem if we change the signature of Decorator 
> as it will break existing applications and Decorator is used by Tree 
> and PropertySelect as well.
>
> Will have to think a bit how we can introduce attribute manipulation 
> at the cell level without impacting existing apps.
>
> kind regards
>
> bob
>
> sven.pfeiffer@madsep.de wrote:
>> I am wondering if it would be nice if the decorator has the
>> capability to change the column style.
>>
>> I guess it would be quite easy if
>>
>> a) the decorator would have a reference to the Column
>> b) the content, which is rendered by the decorator, must be processed 
>> before the
>> Column itself is rendered (rendering = adding it to the 
>> HtmlStringBuffer), this
>> could be done if renderTableDataContent is called at the beginning of
>> renderTableData, storing the result of renderTableDataContent in a 
>> String
>> before putting it to the buffer
>>
>> If you think this is a good idea I could create a patch and open a 
>> jira-issue
>> for the change.
>>
>> Zitat von Bob Schellink <sa...@gmail.com>:
>>
>>> Or a custom Column. At least the method Column#renderTableData would 
>>> have to be adapted to add attributes on a per cell basis.
>>>
>>> kind regards
>>>
>>> bob
>>>
>>>
>>> Malcolm Edgar wrote:
>>>> Hi Sven,to subclass table to do this.
>>>>
>>>> regards Malcol
>>>>
>>>> You will probably need m Edgar
>>>>
>>>> On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
>>>>> Hi list,
>>>>>
>>>>> I'd like to change the background-color of a table row depending 
>>>>> on a value that
>>>>> is displayed in the table.
>>>>> I am showing a table with one row for each day in the current 
>>>>> month, to
>>>>> highlight weekends saturdays and sundays should have a different
>>>>> background-color.
>>>>>
>>>>> Usually I am using Decorator for handling value-objects, but I 
>>>>> don't see a way
>>>>> how to change the background-color of the table-cells.
>>>>>
>>>>> Is there a way to do this?
>>>>>
>>>>> Thanks in advance
>>>>> SVen
>>>>>
>>>>>
>>>>
>>>
>>>
>>
>>
>>
>>
>
>
>


Re: Changing tables background-color depending on a value

Posted by Bob Schellink <sa...@gmail.com>.
I think it might be a problem if we change the signature of Decorator as it will break existing 
applications and Decorator is used by Tree and PropertySelect as well.

Will have to think a bit how we can introduce attribute manipulation at the cell level without 
impacting existing apps.

kind regards

bob

sven.pfeiffer@madsep.de wrote:
> I am wondering if it would be nice if the decorator has the
> capability to change the column style.
> 
> I guess it would be quite easy if
> 
> a) the decorator would have a reference to the Column
> b) the content, which is rendered by the decorator, must be processed 
> before the
> Column itself is rendered (rendering = adding it to the 
> HtmlStringBuffer), this
> could be done if renderTableDataContent is called at the beginning of
> renderTableData, storing the result of renderTableDataContent in a String
> before putting it to the buffer
> 
> If you think this is a good idea I could create a patch and open a 
> jira-issue
> for the change.
> 
> Zitat von Bob Schellink <sa...@gmail.com>:
> 
>> Or a custom Column. At least the method Column#renderTableData would 
>> have to be adapted to add attributes on a per cell basis.
>>
>> kind regards
>>
>> bob
>>
>>
>> Malcolm Edgar wrote:
>>> Hi Sven,to subclass table to do this.
>>>
>>> regards Malcol
>>>
>>> You will probably need m Edgar
>>>
>>> On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
>>>> Hi list,
>>>>
>>>> I'd like to change the background-color of a table row depending on 
>>>> a value that
>>>> is displayed in the table.
>>>> I am showing a table with one row for each day in the current month, to
>>>> highlight weekends saturdays and sundays should have a different
>>>> background-color.
>>>>
>>>> Usually I am using Decorator for handling value-objects, but I don't 
>>>> see a way
>>>> how to change the background-color of the table-cells.
>>>>
>>>> Is there a way to do this?
>>>>
>>>> Thanks in advance
>>>> SVen
>>>>
>>>>
>>>
>>
>>
> 
> 
> 
> 


Re: Changing tables background-color depending on a value

Posted by Bob Schellink <sa...@gmail.com>.
Or a custom Column. At least the method Column#renderTableData would have to be adapted to add 
attributes on a per cell basis.

kind regards

bob


Malcolm Edgar wrote:
> Hi Sven,
> 
> You will probably need to subclass table to do this.
> 
> regards Malcolm Edgar
> 
> On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
>> Hi list,
>>
>> I'd like to change the background-color of a table row depending on a value that
>> is displayed in the table.
>> I am showing a table with one row for each day in the current month, to
>> highlight weekends saturdays and sundays should have a different
>> background-color.
>>
>> Usually I am using Decorator for handling value-objects, but I don't see a way
>> how to change the background-color of the table-cells.
>>
>> Is there a way to do this?
>>
>> Thanks in advance
>> SVen
>>
>>
> 


Re: Changing tables background-color depending on a value

Posted by Malcolm Edgar <ma...@gmail.com>.
Hi Sven,

You will probably need to subclass table to do this.

regards Malcolm Edgar

On Thu, Dec 10, 2009 at 10:56 AM,  <sv...@madsep.de> wrote:
> Hi list,
>
> I'd like to change the background-color of a table row depending on a value that
> is displayed in the table.
> I am showing a table with one row for each day in the current month, to
> highlight weekends saturdays and sundays should have a different
> background-color.
>
> Usually I am using Decorator for handling value-objects, but I don't see a way
> how to change the background-color of the table-cells.
>
> Is there a way to do this?
>
> Thanks in advance
> SVen
>
>