İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
9737 Görünümler

When I add

widget="many2many_checkboxes" 

to a m2m field, it will show them by their ids (id=1, id=2,...). Is there a way to show them in their name's alphabetical order? 

Normally when I display m2m in a tree, i can use default_order="name desc" but in here

<field name="categ_ids" widget="many2many_checkboxes" default_order="name desc"/>

does nothing.

Avatar
Vazgeç
En İyi Yanıt

Hello Anti Nuga,

     You have to replace some line of code(template) in xml file..

here is path: addons >> web >> static >> src >> xml >> base.xml


<t t-name="FieldMany2ManyCheckBoxes">
    <t t-set="total_rec_value" t-value="0"/>
    <t t-set="rec_value" t-value="[]"/>
    <t t-foreach="widget.get('records')" t-as="record">
        <t t-set="rec_value[total_rec_value]" t-value="widget.get('records')[total_rec_value][1]"/>
        <t t-set="total_rec_value" t-value="total_rec_value + 1"/>
    </t>
    <t t-set="rec_value" t-value="rec_value.sort()"/>
    <t t-foreach="rec_value" t-as="rv">
        <t t-foreach="widget.get('records')" t-as="record">
            <t t-if="record[1] == rv">
                <div>
                    <label style="font-weight: normal">
                        <input type="checkbox" t-att-data-record-id="JSON.stringify(record[0])"
                               t-att-checked="selected[record[0]] or null"/>
                        <t t-esc="record[1]"/>
                    </label>
                </div>
            </t>
        </t>
    </t>
</t>


Hope this will help you, Thanks!

Avatar
Vazgeç
Üretici

Works fine, only thing I noticed that it will sort stuff with capital first letter first and then the words with lower case first letter. e.g. 'asd', 'Foo','A' goes to 'A','Foo','asd'. This is just an observation, otherwise it works fine. Thanks!

Hi hardik, i dont want to show in ascending or descending but i want to show in order what we selected. Can u please help?

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Haz 22
5905
2
Ağu 20
10764
2
Eyl 17
9987
1
Nis 17
19353
1
Mar 15
11609