Template Repeater - Rearrange items by clicking and dragging

Hi,

One for the Java experts out there looking for a challenge!

I have a template repeater that displays recipe steps and their configuration using a dataset parameter that is initially populated via a SQL query.

I might be dreaming, but I’m wondering how difficult it would be to allow a user to click and drag the steps around as you can in other applications in order to re-order the steps? How would one achieve this, if at all remotely possible?

Cheers!

Nick

I’ve done something similar, but only with a table.
I guess you can imagine your steps as a row (which probably are).
My table had data property bonded to SQL query:

SELECT id, sifra, folderid, sort_order, op, par1/1000.0 as par1, par2/1000.0 as par2, speed as speed, options, modifiedby, t_stamp, 0 "delete" FROM sifre_krivljenje_koraki 
WHERE sifra = '{ignitionomg/izbranaSifra}'
ORDER BY sort_order

I had a column named sort_order (for you would be a step number) and I’ve changed only that value. On the table side, I had two buttons for UP and DOWN and in the buttons actionPerformed I have:

table = event.source.parent.getComponent('PowerTable')
selected_sort_order = table.data.getValueAt(table.selectedRow,"sort_order")
#UP
res = system.db.runPrepUpdate("UPDATE sifre_krivljenje_koraki SET sort_order = 2 * ? - sort_order - 1 WHERE sort_order IN (?, ?)", [selected_sort_order, selected_sort_order - 1, selected_sort_order])
system.db.refresh(table, "data")
table.selectedRow = table.selectedRow - 1

table = event.source.parent.getComponent('PowerTable')
selected_sort_order = table.data.getValueAt(table.selectedRow,"sort_order")
#DOWN
res = system.db.runPrepUpdate("UPDATE sifre_krivljenje_koraki SET sort_order = 2 * ? - sort_order + 1 WHERE sort_order IN (?, ?)", [selected_sort_order, selected_sort_order, selected_sort_order +1])
system.db.refresh(table, "data")
table.selectedRow = table.selectedRow + 1

I guess you can put the code for UP and DOWN buttons (with some modifications) inside your drag&drop events…

I don’t know about drag/drop, but I was able to make something work with up/down arrows to the side of my template repeater. Here are my rough steps:

  • Add a column in my database to store the templates location in the repeater (index).
  • In the query used in the template repeater, add an ORDER BY by that order column.
  • Add a checkbox (toggle button) to the template so that the user can select a template.
  • Add up button on the side (outside the template repeater) that when pressed gets the selected templates order, and swaps it with the order of the template right above it.
  • Add a down button that swaps the order of the selected template with the one below it. (In the database).
  • Once a button is pressed, refresh the template repeater so that the change is reflected.
  • I also added code to the checkbox on the template so that when a box was checked, it would de-select all the other check boxes in their respective templates.

Probably more things I’m forgetting.

1 Like

Here is an example I posted of reordering table rows.

This uses a different method than how I approached the template repeater.

It is possible, but it is quite involved.

Here is a video as an example. Both a free form and structured layouts.
https:/uploads/iatesting/original/2X/a/a1eb7b09ac6d68dd120f2e115784dfcc693863cb.mp4

1 Like