Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
27378 Zobrazení

I need to conditionally format a report template for Quotation:

....<tbody class="sale_tbody">

<t t-foreach="o.order_line" t-as=i">

<tr t-if="something">                     // <<< Have to set CSS depending on condition here

<td><span t-field="i.name" /></td>

</tr>

</tbody>

In the code snippet, I basically want to change the background colour of the row based on a value in the order_line table (like quantity less than 4 etc.)

I have been struggling to do it. I have tried to use t-if and t-att, but I can't understand how to change CSS format with the conditions.

Can anyone please help me out on this?

 

Avatar
Zrušit
Nejlepší odpověď

You have to write to conditions to change the formating.

<tbody class="sale_tbody">
    <t t-foreach="o.order_line" t-as=i">
        <tr t-if=="value1">                     
            <td><span t-field="i.name" /></td> // <<< Have to set CSS depending on condition here
        </tr>
        <tr t-if=="value2">                     
            <td><span t-field="i.name" /></td> // <<< Have to set CSS depending on condition here
        </tr>
    </t>
</tbody>

Avatar
Zrušit
Autor Nejlepší odpověď

There is actually a better way to do this, as I just found out:

<t t-if-"value1">
      <t t-set="style" t-value="'color:blue'" />
</t>
<t t-if-"value2">
      <t t-set="style" t-value="'color:red'" />
</t>
                        
<span t-att-style="style" >Test</span>

 

Avatar
Zrušit
Nejlepší odpověď

Some of the syntax error, logic is right, Updated answer:

<t t-if="value1">

<t t-set="style" t-value="'color:blue'" />

</t>

<t t-if="value2">

<t t-set="style" t-value="'color:red'" />

</t>

<span t-att-style="style" >Test</span>

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
pro 23
18452
1
srp 17
6288
3
dub 25
1496
2
kvě 24
2150
0
kvě 24
55