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

I want to change position number field to left in list view odoo 16. I tried:   style="text-align: left" and type="char" but not working for me.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for your help. I have tried both ways ,but it's still not working. :((


คำตอบที่ดีที่สุด

By default, Odoo aligns numeric fields to the right in both the header and body of tree views. To left-align a specific field, you can patch the ListRenderer and adjust the DOM once it's mounted.


Here’s how I solved it using JavaScript in Odoo 16+ (OWL architecture):


/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { ListRenderer } from "@web/views/list/list_renderer";
import { onMounted } from "@odoo/owl";
patch(ListRenderer.prototype, "align_left_area_size", {
    setup() {
        this._super(...arguments);

        onMounted(() => {
            const headers = document.querySelectorAll('div[name="one2many_ids"] th[data-name="integer_field"]');
            const cells = document.querySelectorAll('div[name="one2many_ids"] td[name="integer_field"]');

            headers.forEach((el) => {
                el.classList.remove("text-end");
                el.style.textAlign = "left";
                const labelSpan = el.querySelector("span.text-end");
                if (labelSpan) {
                    labelSpan.classList.remove("text-end");
                    labelSpan.style.textAlign = "left";
                }
            });
            cells.forEach((el) => {
                el.style.textAlign = "left";
            });

            document.querySelectorAll('div[name="one2many_ids"] th[data-name="integer_field"] div.d-flex').forEach((div) => {
                div.classList.remove("text-end", "flex-row-reverse");
            });
        });
    },
});


This works for fields in nested One2many lists too, and you can adapt the selector for any other field. (I invite you to inspect the elements on your navigator to local better your field) 

Don't forget to add your file in the assets of your module's manifest.

I hope this helps!

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

Hi

Try this inside a css file 

th.o_column_sortable[data-name="field_name"]

{

text-align: center;

}


Hope it helps

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

Hi BB,

Try class="text-left",




Hope it helps.
Kiran K

อวตาร
ละทิ้ง

<field name="date" class="text-left"/>
<field name="amount" class="text-right"/>

Related Posts ตอบกลับ มุมมอง กิจกรรม
5
พ.ย. 23
42968
Create dynamic tree view แก้ไขแล้ว
3
ก.ย. 23
9460
1
ก.ย. 22
3731
1
มิ.ย. 22
12552
3
มี.ค. 20
11020