Setting style per dataview item

Hi,

is it possible to set a style per item in a dataview?
I have several items in a dataview and they have a status: assigned or unassigned. Depending on this status I want the background color of the item to be green or the default color.

I tried it like this:

view = dhxLayout.cells("a").attachDataView({ type:{ template: function(obj){return obj.status+"<br>"+obj.Company+" :"+obj.Task+"<br/>"+obj.Description+"</div>"}, css:function(obj){if(obj.status=="assigned"){return "green"} else {return ""}} })

But that doesn’t seem to work, do you have some advice on how to handle this?

kind regards,
Arno.

Hi,

css needs being string, not template. For example:
{
css: “green”

}

sets dhx_dataview_green_item class name for each dataview item (instead of dhx_dataview_item).

If you need to set color depending on item property, you should do this in template:

view = dhxLayout.cells("a").attachDataView({ type:{ template: function(obj){ return "<div style='background-color:"+(obj.status=="assigned"?"green":"#ffffff")+";width:100%;height:100%'>"+obj.status+"<br>"+obj.Company+" :"+obj.Task+"<br/>"+obj.Description+"</div>" }, padding:0 })

Thanks Alexandra.
I will try this approach.

kind regards,
Arno.