dg2 row re-ordering

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

dg2 row re-ordering

Post by marksmithhfx » Sat Jan 09, 2021 1:28 pm

Is there a quick and easy way in LC to tell if a DG2 has had its rows re-ordered? I have a DG2 that currently lets users: add/delete rows, edit rows, and modify widgets and all of these are detectable and can be used to trigger a save to disk (for permanent storage). However, for row re-ordering I have not figured out a way to detect if this has happened and hence the file on disk needs updating, short of saving every time I leave the current card/page. The cost of saving when unnecessary is actually extremely low and goes unnoticed but I was trying to eliminate it anyway.

Thanks
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: dg2 row re-ordering

Post by Klaus » Sat Jan 09, 2021 2:24 pm

Hi Mark,

how can your user "re-order" your dg?
No script(s) involved where you can "hook on"?


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: dg2 row re-ordering

Post by dunbarx » Sat Jan 09, 2021 6:58 pm

Hi.

Save the order, or the entire order "history", in a custom property. Then you can restore it at will, anywhere in the list. This begs the issue of the user changing the contents, as opposed to the line order. You have to watch how and when you update that history.

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: dg2 row re-ordering

Post by marksmithhfx » Tue Jan 12, 2021 3:00 pm

Klaus wrote:
Sat Jan 09, 2021 2:24 pm
how can your user "re-order" your dg?
No script(s) involved where you can "hook on"?
Klaus
Hi Klaus, in the new dg2 there is a control you can enable on the right side of the DG that allows re-ordering rows (it is part of dgEditMode in DG2). However, I don't see anyway to actually be notified that a re-ordering has taken place. There are no api's to this function that I can see. I could spin my own but frankly, there are more downsides than upsides. What I do now is just save the whole dg out to disk in the correct order and load it back in the same order. That takes about 1/10 of a second ie. not really noticeable.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: dg2 row re-ordering

Post by marksmithhfx » Tue Jan 12, 2021 3:14 pm

dunbarx wrote:
Sat Jan 09, 2021 6:58 pm
Save the order, or the entire order "history", in a custom property. Then you can restore it at will, anywhere in the list. This begs the issue of the user changing the contents, as opposed to the line order. You have to watch how and when you update that history.

Craig
Hi Craig,

That's more or less what I do now (to an sqlite file instead of custom property). At present if you add or edit records I update the file in real time. I was concerned that might be noticeable or indicate a lag (so it was not in the original design), but it turns out it's so fast its no problem at all. When I add new records I put the RecNo from the sqlite file in the DG. Later, for individual record edits, I can issue an update for that one record by RecNo, so it's direct and fast. The design at present has the disk file mirroring the dg in all situations except re-ordering rows. For that I just flush the whole dg to disk when the user leaves the "page". Again, very quick so not really a downside other than it's unnecessary if no re-ordering has occurred.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: dg2 row re-ordering

Post by Klaus » Tue Jan 12, 2021 3:31 pm

marksmithhfx wrote:
Tue Jan 12, 2021 3:00 pm
Klaus wrote:
Sat Jan 09, 2021 2:24 pm
how can your user "re-order" your dg?
No script(s) involved where you can "hook on"?
Klaus
Hi Klaus, in the new dg2 there is a control you can enable on the right side of the DG that allows re-ordering rows (it is part of dgEditMode in DG2)...
ah, I see.

Yes, there is no API for this so I would save my data "prophylacticly" after each:

Code: Select all

...
set the dgEditMode of group "your dg here" to false
## Write back to disk...
...
what you obviously already do.


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”