2. Dragging rows between grids
Dragging rows inside and between grids
- See Row moving and dragging documentation and Default rows documentation.
-
Example description
- Move row with children by dragging by left mouse button, copy row by dragging by right mouse button, copy row with children by dragging by ctrl+right mouse button.
Select more rows (by panel button) and drag them together.
- There are three row types (default rows), NODE, ITEM and SUBITEM. The NODE can contain only ITEM. The ITEM can contain ITEM and SUBITEM. The SUBITEM can contain only SUBITEM.
- New child in NODE is ITEM. New child in ITEM is SUBITEM. New child in SUBITEM is SUBITEM.
- The Tree and Nodes grids can contain all rows (NODE, ITEM, SUBITEM), root rows are NODE. The Items grid can contain ITEM and SUBITEM rows, root rows are ITEM.
The Subitems grid does not accept new rows.
- Rows dragged from Tree, Nodes and Items grids are moved (or copied if dragged by right or middle mouse button) and rows dragged from Subitems grid are always copied.
-
Basic dragging settings
are described in the previous example, see 01-Dragging_and_copying_rows tutorial.
Dragging permissions
By default it is permitted to drag rows between grids.
Set <Cfg Dragging='0'/> to restrict dragging from the grid, set <Cfg Dropping='0'/> to restrict dropping rows to the grid.
On row level set row attribute CanDrag
to 0 to restrict dragging the row.
Dragging permissions can be controlled dynamically by API event OnStartDrag, dropping permissions by API event OnCanDrop.
API
On move row to another grid there is called OnRowMoveToGrid API event.
Move row(s) to another grid by MoveRowsToGrid API method.
Save changes to server
-
Moved row to another grid is not marked by Moved attribute. It is marked as
Deleted='1'
in source grid and Added='1'
in the destination grid.
See XML structure sent to server documentation
-
If the destination grid contains Deleted='1' row with the same id as moved row (when moving row back to source grid), the row is not added, but the original deleted row is undeleted and its cells are copied from the moved row.
The source row is still marked as Deleted='1' in this case, so there is deleted row in source grid, but not added row in the destination grid.
Use OnRowCopyId API event to preserve the row id when moving to provide the behavior described above.
-
Because the move changes two grids it is good to save all grids together to have their state always synchronized.
To do it create function that will read the grid changes by GetXmlData API method and merge them together and send them to server. After the save is done, call AcceptChanges API method for all grids.
-
Undo feature is not fully compatible with moving rows between grids. It undoes changes only in one grid, so there can be inconsistent state, when the moving action is undone only in one grid.