onDrop method broken?

Questions, tips and tricks and techniques for scripting in Servoy

onDrop method broken?

Postby alexander.sternadel » Mon Dec 30, 2024 10:52 am

Hi everyone,

I'm following the servoy video "Drag and Drop within and between data grids" https://www.youtube.com/watch?v=_T7qEJfXEp8
and found that it does not work on my installation. The result is either nothing, nothing with warnings or an error of mismatched type.

The difference to the video that I noticed is that in the most recend version the parameter calls for an array and that the paramaeter is in plural with an "s" at the end:
Code: Select all
* Called when a row is dropped as a result of a drag-n-drop.
*
* @param {Array<JSRecord>} sourceRecords
* @param {JSRecord} targetRecord
* @param {JSEvent} event


Leaving the paramaters as they are or changing them to whats in the video does not work.
The developer also gives out a warning:
Code: Select all
The property sort_key is undefined for the type JSRecord


or an error
Code: Select all
TypeError: Cannot call method "sort" of undefined


Does anyone have any clue on this?

Cheers
Alexander
alexander.sternadel
 
Posts: 20
Joined: Fri Nov 22, 2024 1:33 pm

Re: onDrop method broken?

Postby swingman » Mon Dec 30, 2024 11:25 am

Hi Alexander,

which version of Servoy are you on? I'm having problems getting this to work on Servoy 2023.03 NG Client. However, it seems that things are partially working in your case.

sort_key is the column you are using to sort the records. It may be called something different in your database table.
sort is a standard method on a foundset, so it sounds like you code is not correctly referencing the foundset of your grid component.

hope this helps,

Christian
Christian Batchelor
Certified Servoy Developer
FullStackDesign.it
Venice, Italy | London, UK
http://www.fullstackdesign.it

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1483
Joined: Wed Oct 01, 2003 10:20 am
Location: Venice / London

Re: onDrop method broken?

Postby alexander.sternadel » Mon Dec 30, 2024 11:54 am

Hi Christian,

I'm running 2024.9.1.4003 with NG-Grids on 2024.9.4

Naming of sort_key is correct in my database. Checked it before posting. Type is INTEGER.
Neither the sort method is working, nor simple caluclations like sort_key + 1
It seems like the function is not finding or using the foundset properly to add the correspoding record into (sourceRecords, targetRecord)

Is there a special way needed to place it in the parameter?
I tried so far:
Code: Select all
@param {Array<JSRecord>}
@param {Array<JSRecord<db:/pqi/documents>>}
@param {JSRecord<db:/pqi/documents>}
alexander.sternadel
 
Posts: 20
Joined: Fri Nov 22, 2024 1:33 pm

Re: onDrop method broken?

Postby swingman » Tue Dec 31, 2024 6:51 pm

You need to work with the array of source records and the target record.
The actual foundset is irrelevant here.

I would replace the placeholders with:

Code: Select all
@param {Array<JSRecord<db:/pqi/documents>>} sourceRecords
@param {JSRecord<db:/pqi/documents>} targetRecord
@param {JSEvent} event


C
Christian Batchelor
Certified Servoy Developer
FullStackDesign.it
Venice, Italy | London, UK
http://www.fullstackdesign.it

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1483
Joined: Wed Oct 01, 2003 10:20 am
Location: Venice / London

Re: onDrop method broken?

Postby alexander.sternadel » Thu Jan 02, 2025 7:13 am

I tried this setting of the placeholders already, but nothing seems to work.

Code: Select all
sourceRecords.doc_sortkey = targetRecord.doc_sortkey + 1;
like in the tutorial does not update anything.

Code: Select all
application.output(sourceRecords.doc_sortkey,LOGGINGLEVEL.INFO);
gives me NULL even if all the records in the DB a prefilled with numbers.
alexander.sternadel
 
Posts: 20
Joined: Fri Nov 22, 2024 1:33 pm

Re: onDrop method broken?

Postby jcompagner » Thu Jan 02, 2025 10:03 am

sourceRecords is an array....

application.output(sourceRecords[0].doc_sortkey,LOGGINGLEVEL.INFO);
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8901
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onDrop method broken?

Postby alexander.sternadel » Thu Jan 02, 2025 10:26 am

Thank you! That solved it...

But that also means that the video is outdated? Since the onDrop function now calls for an array and the video shows a JSRecord.
alexander.sternadel
 
Posts: 20
Joined: Fri Nov 22, 2024 1:33 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 1 guest

cron