Vinod
Vinod

Reputation: 32861

How to do Sorting and Indexing of data in between on Cloud Firestore?

I am working on a Task list Angular application. When I add data into my Firestore collection, i add them with creation date and time. So when i retrieve the records back i can easily order them by creation date.

This is fine so far. But i have to simulate something like a notepad application for Tasks.

If we enter Task1 Task2 Task3 Tesk4. So far its good.

But now if i want to Add Task5 between Task3 and 4, i am stuck. My Task5 always comes in the end. This is because i use creation datetime for sorting.

Please help me with a simple idea to be able to insert items in between the existing list and retrieve data accordingly.

I want the result to be like Task1 Task2 Task3 Task5 Task4

Upvotes: 1

Views: 57

Answers (1)

Yatima
Yatima

Reputation: 168

How about this;
increment for adding a doc to last,
decrement for adding a doc to first,
the average for adding a doc between the docs.

I mean,

Task1
  order:1
Task2
  order:2
Task3
  order:3
Task4
  order:4

 

Task1
  order:1
Task2
  order:2
Task3
  order:3
Task5
  order:3.5
Task4
  order:4

 

Task6
  order:0
Task1
  order:1
Task2
  order:2
Task3
  order:3
Task5
  order:3.5
Task4
  order:4

Upvotes: 0

Related Questions