Record `position` not returning updated positions

Describe the issue:

I’m doing a pretty simple query to get the position of my Project models that are ordered via drag and drop. I have deleted a Project and reordered another, but it looks like the positions haven’t updated to reflect deleted model. You can see here it skips from 10 to 12 in the query, and again from 12 to 14.

I’m not sure if this is because there is a 3 day history retention on the developer plan, so it hasn’t yet updated? If this is the case, is there a way to refresh the query and wipe the history, as I don’t want the deleted page to exist anymore, and don’t want to wait 3 days for this to refresh either? If this isn’t the problem though, any help would be appreciated.

Thanks!

Hey @lbirchall, I’m not sure if that is intentional behavior, but I’ll check with the devs for you. In the meantime, you can pretty easily sort or reindex them on the frontend if you need a quicker workaround:

const exampleRecords = [
    {
        "title": "Twenty",
        "position": 20
    },
    {
        "title": "One",
        "position": 1
    },
    {
        "title": "Three",
        "position": 3
    },
    {
        "title": "Four",
        "position": 4
    },
    {
        "title": "Seven",
        "position": 7
    }
]

const sortedRecords = exampleRecords.sort((a, b) => a.position - b.position);
console.log(sortedRecords)
/* e.g.
    [
    { title: 'One', position: 1 },
        { title: 'Three', position: 3 },
        { title: 'Four', position: 4 },
        { title: 'Seven', position: 7 },
        { title: 'Twenty', position: 20 }
    ]
*/


const sortedRecordsWithNewPositions = sortedRecords.map((record, index) => ({...record, newPosition: index}))
console.log(sortedRecordsWithNewPositions)

/* e.g.
[
  { title: 'One', position: 1, newPosition: 0 },
  { title: 'Three', position: 3, newPosition: 1 },
  { title: 'Four', position: 4, newPosition: 2 },
  { title: 'Seven', position: 7, newPosition: 3 },
  { title: 'Twenty', position: 20, newPosition: 4 }
]
 */

In that example, you should be able to use the sortedRecordsWithNewPositions and their newPosition property to do whatever you needed with sequential positions.

Hey @lbirchall

After checking, this is a conscious decision, as the position integer (also available in the sidebar of the record)

Is not related with the number of records in a model, as you can see, you can put a record in a position of 200 even if the model does not have that number of records.

So if a record has its position set to “3” and the record “2” is deleted, it’s position will not be changed, only if the editor manually goes into the sidebar and changes that integer