Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
9078 Lượt xem

Hello , I am trying to sort my records in my tree view , I have a selection field called as _STATES when I try to sort my view according to that , it sorts in correctly, my code and details:

py code

_STATES = [
('1_draft', 'To - Do'),
('10_in_progress', 'In Progress'),
('20_approval', 'Approval'),
('30_closed', 'Closed'),
('40_cancelled', 'Cancelled')
]


state = fields.Selection(_STATES, 'State', required=True, default="1_draft"
)


XML Code

<tree string="Action">
<field name="name"/>
    <field name="state"/>
</tree>

When I click states field on my tree view to sort my records , it sorts them incorrectly.

The sorting my model makes:

1)10_in_progress

2)1_draft

3)20_approval

4)30_closed

5)40_cancelled


The sorting I want to have:

1)1_draft

2)10_in_progress

3)20_approval

4)30_closed

5)40_cancelled

Ảnh đại diện
Huỷ bỏ

Will it work if you change the first one to 01_draft?

Câu trả lời hay nhất

As mentioned in the existing answers you are trying to sort according to the string. So better to give selection values in sort order. For example.


1)a_draft

2)b_in_progress

3)c_approval

4)d_closed

5)e_cancelled


Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks , this worked.

Câu trả lời hay nhất

You need to do customization for it. selection key values are string and it can not be sorted as per numbers. Another way you can assign a number to the records based on selection key and then you can easily do sorting base on that field. 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
25854
1
thg 3 17
6515
1
thg 3 15
4867
0
thg 2 21
2680
1
thg 4 23
4010