Skip to main content
Solved

Drag and drop row change?

  • February 11, 2021
  • 1 reply
  • 160 views

Can i change in the row with drag and drop? 

 

Best answer by Mark Jongeling

Hi,

I made a little example for you and this should be enough for you to get going :wink: :

Drag and drop

Task screen

Start off by making a Task that has 2+PK amount of parameters. We need the PK columns as Parameters, one from_order_no  and one to_order_no as we need to know where the user drags to. The parameters can be hidden.

Next up, connect the task to the desired table at Table tasks. We only need to connect one Task parameter at Table task parameters as the Drag and drop will fill the other parameters.

 

Subject screen

At Subjects, search up the desired table and navigate to the tab Links > Drag-drop. Create an entry here by having the source tab and target tab equal, selecting your drag-drop task and choosing the Move effect. On the Drag-drop parameters tab, make sure your PK parameters and the from_order_no is Passed as value. Then on the Drag-drop interaction tab, make sure it is allowed to Drag-drop on the desired table and/or variant. Sometimes we would like to be able to drag-drop in certain screens but not in others.

In Subject > Settings, you may choose to check the box Def. drag-drop enabled. Like the name implies, the user can drag-drop immediatly when entering the screen. Leaving this off will result in the user having to enable this in the List of the subject.

 

Functionality screen

The Task of course needs some coding. Make an entry in Functionality for the task. Make a Template (or generate one by assigning the template first to the Task) and use the following code:

/* Continue if different */
if @from_order_no <> @to_order_no
begin
    /* Copy all records into #temp */
    select *
      into #temp
      from [table] t

    /* Make space for reorder */
    update t
       set t.order_no = order_no * 10
      from #temp t

    /* Alter order no of dragged row (+1/-1 depending higher/lower dragging) */
    update t
       set t.order_no = @to_order_no * 10 + iif(@to_order_no < @from_order_no, -1, 1)
      from #temp t 
     where t.id = @id /* PK columns */

    /* Reorder all items */
    ;with reorder_order_no as (
        select t.id /* PK columns */
              ,row_number() over (order by t.order_no asc) as new_order_no
        from #temp t
    )
    update t
       set t.order_no = new_o.new_order_no
      from [table] t
      join reorder_order_no new_o
        on new_o.id = t.id /* PK columns */
end

Note that this script includes [table], this is a parameter that can be automatically filled upon generating with a value you can set in Functionality > Assigning > Assigned templates > Parameters. Create an entry if not already there giving in the following values:

  • Parameter = table
  • Parameter value = your table name

This leaves you with Generating and deploying the code onto the database in Result

Now drag and drop should function in your application!

Had to alter the gif, sorry for the poorer quality​​​​​

 

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

1 reply

Mark Jongeling
Administrator
Forum|alt.badge.img+23
  • Administrator
  • 3936 replies
  • Answer
  • February 15, 2021

Hi,

I made a little example for you and this should be enough for you to get going :wink: :

Drag and drop

Task screen

Start off by making a Task that has 2+PK amount of parameters. We need the PK columns as Parameters, one from_order_no  and one to_order_no as we need to know where the user drags to. The parameters can be hidden.

Next up, connect the task to the desired table at Table tasks. We only need to connect one Task parameter at Table task parameters as the Drag and drop will fill the other parameters.

 

Subject screen

At Subjects, search up the desired table and navigate to the tab Links > Drag-drop. Create an entry here by having the source tab and target tab equal, selecting your drag-drop task and choosing the Move effect. On the Drag-drop parameters tab, make sure your PK parameters and the from_order_no is Passed as value. Then on the Drag-drop interaction tab, make sure it is allowed to Drag-drop on the desired table and/or variant. Sometimes we would like to be able to drag-drop in certain screens but not in others.

In Subject > Settings, you may choose to check the box Def. drag-drop enabled. Like the name implies, the user can drag-drop immediatly when entering the screen. Leaving this off will result in the user having to enable this in the List of the subject.

 

Functionality screen

The Task of course needs some coding. Make an entry in Functionality for the task. Make a Template (or generate one by assigning the template first to the Task) and use the following code:

/* Continue if different */
if @from_order_no <> @to_order_no
begin
    /* Copy all records into #temp */
    select *
      into #temp
      from [table] t

    /* Make space for reorder */
    update t
       set t.order_no = order_no * 10
      from #temp t

    /* Alter order no of dragged row (+1/-1 depending higher/lower dragging) */
    update t
       set t.order_no = @to_order_no * 10 + iif(@to_order_no < @from_order_no, -1, 1)
      from #temp t 
     where t.id = @id /* PK columns */

    /* Reorder all items */
    ;with reorder_order_no as (
        select t.id /* PK columns */
              ,row_number() over (order by t.order_no asc) as new_order_no
        from #temp t
    )
    update t
       set t.order_no = new_o.new_order_no
      from [table] t
      join reorder_order_no new_o
        on new_o.id = t.id /* PK columns */
end

Note that this script includes [table], this is a parameter that can be automatically filled upon generating with a value you can set in Functionality > Assigning > Assigned templates > Parameters. Create an entry if not already there giving in the following values:

  • Parameter = table
  • Parameter value = your table name

This leaves you with Generating and deploying the code onto the database in Result

Now drag and drop should function in your application!

Had to alter the gif, sorry for the poorer quality​​​​​

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings