# Custom sorting not working

**URL:** <https://community.vikunja.io/t/custom-sorting-not-working/1170>\
**Category:** Bug\
**Created:** [21 February 2023 23:38 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170 "2023-02-21T23:38:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Okamikun](https://community.vikunja.io/letter_avatar_proxy/v4/letter/o/5daacb/32.png) [@Okamikun](https://community.vikunja.io/u/Okamikun)\
**Post date:** [21 February 2023 23:38 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/1 "2023-02-21T23:38:56Z")

</div>

Hi community,

I got Vikunja to work on my Synology a few weeks ago and love the app!

One thing I would like to do, is custom sorting the tasks I created. In a List I can drag and drop the tasks but after reloading the page, or moving to another List and back, the original order is shown.

Apart from that, is it possible to custom sort tasks on the Upcoming view?

When testing it again right now, I realized that I am able to sort tasks in a new list. However, after a few minutes, the sorting is not consistent anymore.

Example:

- Want to sort tasks in list “General” → not working
- Create new list “Test” with dummy entries → sorting works
- Create new Namespace “general” and duplicate list “General” into namespace “general” → sorting works
- wait a few minutes → sorting stops working in list “general” and in list “Test” as well

Did anybody encounter an error like this in the past?  
I am using vikunja on Brave, where the api and frontend are running in Docker containers in my Synology.

Best regards,  
Fabian

---

<div class="post-metadata">

**Author:** ![kolaente](https://community.vikunja.io/user_avatar/community.vikunja.io/kolaente/32/5_2.png) [@kolaente](https://community.vikunja.io/u/kolaente)\
**Post date:** [22 February 2023 10:06 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/2 "2023-02-22T10:06:56Z")

</div>

> [@Okamikun](#):
>
> Apart from that, is it possible to custom sort tasks on the Upcoming view?

That’s not possible right now.

> [@Okamikun](#):
>
> In a List I can drag and drop the tasks but after reloading the page, or moving to another List and back, the original order is shown.

I was unable to reproduce this. Can you check if it works on [try](https://try.vikunja.io)?

---

<div class="post-metadata">

**Author:** ![Okamikun](https://community.vikunja.io/letter_avatar_proxy/v4/letter/o/5daacb/32.png) [@Okamikun](https://community.vikunja.io/u/Okamikun)\
**Post date:** [23 February 2023 01:26 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/3 "2023-02-23T01:26:41Z")

</div>

Thanks for the reply!

On [try.vikunja.io](http://try.vikunja.io) I have the exact same behavior. Tried it on Android with Chromium and iPhone with Safari. I didn’t connect to my own backend.

Here is a screen record from the iphone test (sorry for the music xD)

---

<div class="post-metadata">

**Author:** ![cernst72](https://community.vikunja.io/user_avatar/community.vikunja.io/cernst72/32/595_2.png) [@cernst72](https://community.vikunja.io/u/cernst72)\
**Post date:** [23 February 2023 11:23 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/4 "2023-02-23T11:23:25Z")

</div>

I stumbled across this too.

If you look at the tasks with curl (or [vja](https://pypi.org/project/vja/) 🙂 ) you will find that a lot of tasks have their attributes `position` and `kanban_position` set to 0.

It seems that the algorithm for moving a task within a list assigns its new position/kanban\_position to a value between the upper and the lower task which is 0 between 0 and 0 and thus will be ignored.

The current algorithm will soon fill up un-movebale position 0-tasks as long as Vikunja emits positions as 0 for new tasks and accepts 0 from other clients like caldav.

---

<div class="post-metadata">

**Author:** ![kolaente](https://community.vikunja.io/user_avatar/community.vikunja.io/kolaente/32/5_2.png) [@kolaente](https://community.vikunja.io/u/kolaente)\
**Post date:** [23 February 2023 15:05 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/5 "2023-02-23T15:05:25Z")

</div>

> [@cernst72](#):
>
> The current algorithm will soon fill up un-movebale position 0-tasks as long as Vikunja emits positions as 0 for new tasks and accepts 0 from other clients like caldav.

I noticed that as well. I tried fixing this in the past with a check in the frontend where it would update the next task as well when it had a position of 0. That works as long as there are not that many tasks with this problem. At some point, most of the tasks have a position of 0 and this naive correction method won’t work anymore.

I’ve just pushed a fix for this in [1efa1696bf](https://kolaente.dev/vikunja/api/commit/1efa1696bf46f5a31d96e7862d33f6e4d275816a). The api will now recalculate the position of all tasks when it notices the position of the current task is \< 0.1. The position attribute might not be correct for all items in the frontend after that, but the positions will stay the same after reloading.  
Please check with the next unstable build (~45 min on try) if the problem went away.

---

<div class="post-metadata">

**Author:** ![cernst72](https://community.vikunja.io/user_avatar/community.vikunja.io/cernst72/32/595_2.png) [@cernst72](https://community.vikunja.io/u/cernst72)\
**Post date:** [23 February 2023 15:47 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/6 "2023-02-23T15:47:26Z")

</div>

Do the recalculateTaskPositions() operations iterate the existing tasks ordered by their position? If not then any existing order would be shuffled, anytime an incoming task without position comes in.  
(Sorry if I’m wrong, I am not very ‘gone’ yet to fully understand the go code.)

---

<div class="post-metadata">

**Author:** ![kolaente](https://community.vikunja.io/user_avatar/community.vikunja.io/kolaente/32/5_2.png) [@kolaente](https://community.vikunja.io/u/kolaente)\
**Post date:** [23 February 2023 16:43 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/7 "2023-02-23T16:43:52Z")

</div>

Good catch! Should be fixed with [ca6d1946da](https://kolaente.dev/vikunja/api/commit/ca6d1946dafc4c9f41f9cdcc3a8e6a8a8fcc00a0).

---

<div class="post-metadata">

**Author:** ![Okamikun](https://community.vikunja.io/letter_avatar_proxy/v4/letter/o/5daacb/32.png) [@Okamikun](https://community.vikunja.io/u/Okamikun)\
**Post date:** [24 February 2023 00:22 UTC](https://community.vikunja.io/t/custom-sorting-not-working/1170/8 "2023-02-24T00:22:06Z")

</div>

Awesome, thank you for the fix!  
It seems to work properly on [try.vikunja.io](http://try.vikunja.io)
