Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
9471 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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?

Gerelateerde posts Antwoorden Weergaven Activiteit
1
jun. 22
5602
2
aug. 20
10479
2
sep. 17
9667
1
apr. 17
19050
1
mrt. 15
11376