Page 2 of 2

Re: [REACT] Get the source index of a reordered row

Posted: Thu Nov 25, 2021 10:34 pm
by mats

That's inconsistent yes, we'll get that fixed. https://github.com/bryntum/support/issues/3816


Re: [REACT] Get the source index of a reordered row

Posted: Fri Nov 26, 2021 8:34 am
by Yamo1993

Awesome, thanks.


Re: [REACT] Get the source index of a reordered row

Posted: Fri Nov 26, 2021 10:13 am
by Animal

Indices in the serialized view are not very useful when dealing with a tree because what do they mean?

A move in a tree means removal of a child node from some position in the children collection of one node and insertion into the children collection of another node.

Visually, it moves to a different row, but if you are sending updates to a back end to tell it what the data state is in a tree stricture, then the operation is a move between two parents.

This information is available in events. This is a record update event. A TreeNode has two important fields which define structure.

  • parentId which identifies its parent
  • parentIndex which defines its position in its parent's children collection.

A change to either of these will result in an update event being fired:

nodemove.gif
nodemove.gif (21.25 MiB) Viewed 221 times

It will look like this:

{
    record: movedRecord,
    records: [movedRecord],
    changes: {
        parentId: {
            value: 9,
            oldValue: 3
        },
        parentIndex: {
            value: 3,
            oldValue: 2
        }
    },
    batch: false,
    source: theStore,
    type: 'update'
}

Re: [REACT] Get the source index of a reordered row

Posted: Fri Nov 26, 2021 10:28 am
by Yamo1993
Animal wrote:
Fri Nov 26, 2021 10:13 am

Indices in the serialized view are not very useful when dealing with a tree because what do they mean?

A move in a tree means removal of a child node from some position in the children collection of one node and insertion into the children collection of another node.

visually, it moves to a different row, but if you are sending updates to a back end to tell it what the data state is in a tree stricture, then the operation is a move between two parents.

This information is available in events. This is a record update event. A TreeNode has two important fields which define structure.

  • parentId which identifies its parent
    parentIndex which defines its position in its parent's children collection.

A change to either of this will result in an update event being fired:

nodemove.gif

It will look like this:

{
    record: movedRecord,
    records: [movedRecord],
    changes: {
        parentId: {
            value: 9,
            oldValue: 3
        },
        parentIndex: {
            value: 3,
            oldValue: 2
        }
    },
    batch: false,
    source: theStore,
    type: 'update'
}

Interesting. Can the "update" event also be used when moving a node within the same parent?

EDIT: I can see now that it does. This is great information, I will try to work with the update event.


Re: [REACT] Get the source index of a reordered row

Posted: Fri Nov 26, 2021 10:37 am
by Animal

Yes. In that case the event will just be simpler:

{
    record: movedRecord,
    records: [movedRecord],
    changes: {
        parentIndex: {  // <-- only the parentIndex has changed
            value: 3,
            oldValue: 2
        }
    },
    batch: false,
    source: theStore,
    type: 'update'
}