Up Arrows Changes Rule Placement


My app has the ability to create rules that the automation follows, and you can create a priority as to what happens first, second, etc… I have a grid that pulls in the rules with their number from a data table, however I’d love to create a way to hit an up or down arrow (or even drag and drop) the order of rules and then when I hit save, it changes which rule is labeled as which number.

Is there an easy way to do this? I can’t get the change of one row to effect the others.

It depends on just how you’re storing the number in the data table, but yes there are ways to do that. It involves updating the data table and reloading the repeating panel in the simplest form.

Here’s some code I use to change the order of an item (lots of error checking removed):

def change_hint_order(hint, adjustment):
    stage = hint['stage']
    num_hints = len(app_tables.hints.search(stage=stage))

    if hint['order']+adjustment < 1:
        raise ValueError("Invalid adjustment")

    if hint['order']+adjustment > num_hints:
        raise ValueError("Invalid adjustment")

    other_hint = app_tables.hints.get(stage=stage, order=hint['order']+adjustment)

    other_hint['order'] -= adjustment
    hint['order'] += adjustment

This would get called by passing a +1 or -1 in as the adjustment, and it assumes that items are ordered from 1 to the number of items.


This is great! Thanks so much for this, just so I can reverse engineer it, what would an example be of the variable “hint” is passing through?

That would be a row from the table you’re reordering items in. For me, the hints table.