Skip to main content

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?

Addition to my previous message:
The functionality should be identical to the way you can change the column order in: subjects → components → Grid


Hi Sergio,

That should be possible I believe. The functionality you are refering to in your reply is task (Stored procedure) task_move_col_grid_order_no

This task knows the following column values:

model_id, branch_id, tab_id, drag_col_id and drop_col_id

Based on that you can know the unique row of the Drag, and of the Drop.

The task definition:

input_set is our Multirow XML parameter

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!


Hi Mark,

Thank you for your response. Based on your answer, it looks like I’m almost there.

I’m just missing one crucial part: the configuration for the column drop_col_id. Where/how do you ensure this gets populated with the correct ID?


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 XML
select 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)
)

insert into @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)')
order by t1.grid_order_no, t1.col_id

Drag_col_id is the column linked to the Task parameter in the Drag-Drop parameter setting:

 


Thank you for your response Mark, it’s working now.


Reply