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

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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?

Related Posts Odpovědi Zobrazení Aktivita
1
čvn 22
5905
2
srp 20
10760
2
zář 17
9986
1
dub 17
19352
1
bře 15
11608