For one of our clients, we want to enable the ability to swap certain rows in a grid using drag-and-drop functionality. For the business logic, it is crucial to know both the ID of the selected row and the ID of the row where the selected object is dropped.
The drag-and-drop action would occur within the same grid/table.
Is this achievable using the standard drag-and-drop functionality?
Best answer by Mark Jongeling
Hey Sergio,
The XML will contain the drop_col_id due to the Table task parameter mapping I believe:
Table task parameter mapping
The GUI will ensure the values are placed in the XML for you to use in logic.
Queries that can help with the drop record:
declare @model_id varchar(100)
declare @branch_id varchar(100)
declare @tab_id varchar(128)
declare @drop_col_id varchar(128)
-- Select context and target key from the XMLselect top 1
@model_id = r.row.value('model_id[1]', 'varchar(100)'),
@branch_id = r.row.value('branch_id[1]', 'varchar(100)'),
@tab_id = r.row.value('tab_id[1]', 'varchar(128)'),
@drop_col_id = r.row.value('drop_col_id[1]', 'varchar(128)')
from @input_set.nodes('rows/row') r (row)
The drag record can potentially be multiple records. All is included in the XML (@input_set for us). The Top 1 ensures we only have one designated drop record.
For the Dragged record(s), we use this query to put it in a temporary table:
-- Select all dragged rows from the XML, using the order as seen on the database.
declare @rows_to_move table (
move_order int identity(1, 1),
drag_col_id varchar(128)
)
insertinto @rows_to_move
select
t1.col_id
from @input_set.nodes('rows/row') r (row)
join col t1
on t1.model_id = @model_id
and t1.branch_id = @branch_id
and t1.tab_id = @tab_id
and t1.col_id = r.row.value('drag_col_id[1]', 'varchar(128)')
orderby t1.grid_order_no, t1.col_id
Drag_col_id is the column linked to the Task parameter in the Drag-Drop parameter setting:
The parameters are configured as Drag-Drop as follows:
Drag-drop configuration
Since for use it is possible that multiple records are being dragged and dropped at the same time, we need to resort to using this multirow task execution method with an XML parameter. Hope this helps!
The XML will contain the drop_col_id due to the Table task parameter mapping I believe:
Table task parameter mapping
The GUI will ensure the values are placed in the XML for you to use in logic.
Queries that can help with the drop record:
declare @model_id varchar(100)
declare @branch_id varchar(100)
declare @tab_id varchar(128)
declare @drop_col_id varchar(128)
-- Select context and target key from the XMLselect top 1
@model_id = r.row.value('model_id[1]', 'varchar(100)'),
@branch_id = r.row.value('branch_id[1]', 'varchar(100)'),
@tab_id = r.row.value('tab_id[1]', 'varchar(128)'),
@drop_col_id = r.row.value('drop_col_id[1]', 'varchar(128)')
from @input_set.nodes('rows/row') r (row)
The drag record can potentially be multiple records. All is included in the XML (@input_set for us). The Top 1 ensures we only have one designated drop record.
For the Dragged record(s), we use this query to put it in a temporary table:
-- Select all dragged rows from the XML, using the order as seen on the database.
declare @rows_to_move table (
move_order int identity(1, 1),
drag_col_id varchar(128)
)
insertinto @rows_to_move
select
t1.col_id
from @input_set.nodes('rows/row') r (row)
join col t1
on t1.model_id = @model_id
and t1.branch_id = @branch_id
and t1.tab_id = @tab_id
and t1.col_id = r.row.value('drag_col_id[1]', 'varchar(128)')
orderby t1.grid_order_no, t1.col_id
Drag_col_id is the column linked to the Task parameter in the Drag-Drop parameter setting:
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.