Skip to Content
Menu
This question has been flagged
1 Reply
2541 Views

Hi

 I want in report to half the number of rows.

 To understand better  :

row

name

row

name

1

a1

3

c3

2

b2

4

d4

<table>

<tr><td> row</td> <td>name</td>   <td> row</td> <td>name</td> </tr>

<tr   t-foreach="showp()" t-as="tt">

<td>  <span t-esc="(tt_index+1)"/> </td>

 <td>  <span t-esc= "tt[0]" /> </td>  

<td>  <span t-esc="(tt_index+1)"/> </td> ??????

<td>  <span t-esc= "tt[0]" /> </td> ??????

</tr>

</table>



 It actually changes in a double for counter.


please help me.

Thanks.

Avatar
Discard
Author

Hi Thanks Ravi Gadhia, but i has error:

Error to render compiling AST

TypeError: 'NoneType' object is not subscriptable

Template:

Path: /templates/t/t/t/t/div/div/t/t/table/t[2]

Node: <t t-set="first_half" t-value="all_data[0]"/>

it means def showp() return None instead of tuple so `all_data` set as None

Best Answer
it's very difficult to manipulate data in qweb you have to pass data in an appropriate format
to qweb so it can render easily

In the above case, you can create two separate data set in python/javascript and server it to qweb like

def showp():
    #..... logic ....
    # result
    half = len(result) // 2
    return result[:half], result[half:]

Qweb template

<t t-set="all_data" t-value="showp()"/>
<t t-set="first_half" t-value="all_data[0]"/>
<t t-set="second_half" t-value="all_data[1]"/>
<tr t-foreach="first_half" t-as="item">
<td t-esc="item_index"/>
<td t-esc="first_half[item_index]"/>
<td t-esc="item_index + len(first_half)"/>
<td t-esc="second_half[item_index]"/>
</tr>          ​          ​            ​

Avatar
Discard