Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
27138 มุมมอง

I want to do something like this, but it does not works:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<tr t-extend="ListView.row" t-att-class="view.class_for(record)">
</tr>
</templates>

Just want to add t-att-class to the tr element. The problem is that tr is the root node, and I cant figure out how to refer it for inheritance. Can someone help me?

The original template looks like this:

<tr t-name="ListView.row"
t-att-data-id="record.get('id')"
t-att-style="view.style_for(record)">
<t t-set="asData" t-value="record.toForm().data"/>
<t t-foreach="columns" t-as="column">
<td t-if="column.meta"> </td>
</t>
<th t-if="options.selectable" class="oe_list_record_selector" width="1">
<t t-set="checked" t-value="options.select_view_id == record.get('id') ? 'checked' : null"/>
<input t-if="options.radio" type="radio" name="radiogroup" t-att-checked="checked"/>
<input t-if="!options.radio" type="checkbox" name="radiogroup" t-att-checked="checked"/>
</th>
<t t-foreach="columns" t-as="column">
<t t-set="number" t-value="column.type === 'integer' or column.type == 'float'"/>
<t t-set="modifiers" t-value="column.modifiers_for(asData)"/>
<td t-if="!column.meta and column.invisible !== '1'" t-att-title="column.help"
t-attf-class="oe_list_field_cell oe_list_field_#{column.widget or column.type} #{number ? 'oe_number' : ''} #{column.tag === 'button' ? 'oe-button' : ''} #{modifiers.readonly ? 'oe_readonly' : ''} #{modifiers.required ? 'oe_required' : ''}"
t-att-data-field="column.id"
><t t-raw="render_cell(record, column)"/></td>
</t>
<td t-if="options.deletable" class='oe_list_record_delete' width="13px">
<button type="button" name="delete" class="oe_i">d</button>
</td>
</tr>

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

try this one. if not working, dig into manual deeper from v7.

<t t-extend="ListView.row">
<xpath expr="//tr[@t-name='Listview.row']" position="attributes">
<attribute name="t-att-class">view.class_for(record)</attribute> <xpath>
</t>
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi Dhinesh,

I have tried your code but does not work for me. Currently I am using this approach that adds the class property at td level, but what I want is to add it at tr level:


<t t-extend="ListView.row">
  <t t-jquery="td[t-att-data-field='column.id']">
  this.attr('t-attf-class', this.attr('t-attf-class') + ' #{view.class_for(record)}');
  </t>
</t>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Your code does not in working

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Its a litte bit late but maybe it will help someone who is also stumbling over this topic.

I'm using the following code to add custom CSS to the rows and to the cells:

<t t-extend="ListView.row">
    <t t-jquery="tr">
        this.context.setAttribute('t-att-class', 'view.class_for(record)');
    </t>
  <t t-jquery="td[t-att-data-field='column.id']">
      this.attr('t-attf-class', this.attr('t-attf-class') + ' {{view.class_for_cell(record, column)}}');
  </t>
</t>

The method "class_for_cell" is an own function to extract the information from the field and set the specific class to the cell.

Working with V8.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You can just use the Qweb Js inheritance by extending the t-name and adding the new class like below:

<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-extend="ListView.row">
        <t t-jquery="tr[t-att-data-id*='record.get('id')']">
            this.attr('t-attf-class', this.attr("t-attf-class") + 'view.class_for(record)');
        </t>
    </t>
</templates>
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 19
8386
0
มิ.ย. 23
1802
How to modify a qweb template? แก้ไขแล้ว
2
ธ.ค. 22
22815
0
ก.ค. 21
2017
Qweb Inheritance แก้ไขแล้ว
3
พ.ย. 19
7641