Challenge: Get List of Visible Portal Rows

Hello everyone,

This is kind of tricky: Is there a way in Servoy to dynamically get (in an HTML calc field, for example) the list of rows a user is currently seeing in a portal? Say a portal shows 100 rows, and the user has scrolled down to Row 23 on a portal that shows 10 rows at a time. I would like to get back a simple HTML table displaying Rows 23 to 32 (again in this example).

Is this at all possible? Could this be done if we use a TabPanel also/instead?

My reason for asking is a (somewhat) petty one: I saw this thread on another forum (Bonjour et bienvenue sur votre nouveau forum! - Le Point d'Arrêt) and I would really like to stick it to 'em! :twisted:

Anyone up to the challenge? I will be happy to post back on the above-mentioned (French) forum, and will give credit where it is due.

Sincerely,

Ben

You could do such a thing based on the last selected index (maybe)…

BTW what is the text of that forum post?

Hi Marcel,

It is a post extolling the virtues of an FM Custom Function that does just what I was talking about earlier, but without all the niceties we can obtain via the custom HTML formatting Servoy allows, of course! It basically says: “Try to do that with Servoy!” So, I would like us to step up to the plate and give them a run for their money. :P

Cheers,

Ben

Hmm, I tend to ignore such stuff (read: never read it).

There is much to argue for both environments that this will end up in an endless effort to bring better arguments to the table than the other :)

Still, it would be nice to know if we can do the same thing in Servoy, and if so, how…

Ben

The example they point to is in english: http://www.briandunning.com/cf/684

Attached is demo Servoy solution and a screenshot.

I don’t quite understand why they want to return a list of of portal numbers. The only useful thing I could come up with is showing the records being viewed as user feedback. So that is what I did.

The good news: you can indeed get the viewable rows in a portal (but not a tab panel) with the elements.portal.getScrollY() function. All other variables that you need can be calculated from the Y size and row height of the portal. As far as abstraction goes you can get the Y size in a method but you have to know the row height ahead of time.

The bad news is when to fire the code. I have it attached to the label button and to the add and delete portal buttons. But there is no Servoy event detecting scrolling. If you’re thinking “Why not put the code in a calculation” think again – you cannot reference form objects in calculations. Well you can but that is a good way to blow your monitor up and in this case it doesn’t quite work all the way. It got my monitor flickering quite dramatically though.

In regards to whoever did http://www.briandunning.com/cf/684 – my only comment is that those guys need to be coding in Servoy. Because if you can put something like THAT together then Servoy is easy beans.

HOWTO

By the way, if you want a lesson in recursive method techiques, you should download the solution and step through the code.

I use one main called method and two global “function” methods.

1- LABEL_portal_index_location (Main method)

/*****

	Returns a list of visible row numbers of a portal
	
	Sample output: "Records 7 to 16 visible"

*****/

//initialize row height variable. portal default is 16
var rowHeight = 16

//get scroll position
var scrollYPos = elements.portal_1.getScrollY()

//call global fx to check if scrollYPos divisible by rowHeight
if (!globals.FX_divisible_check(scrollYPos, rowHeight)) {		

	//if not, call recursive fx to return nearest number to scrollYPos that is divisible by rowHeight			
	scrollYPos = globals.FX_divisible_nearest(scrollYPos, rowHeight)
}

//get visible records. 16 is the default portal row height, 20 is for the header
//NOTE: this means your portal must have a Y size that is divisible by 16 plus 4!
//in this demo the portal Y size is 16 * 16 + 4 = 260
var recVisible = (elements.portal_1.getHeight() - 20) / rowHeight

//get visible start and end record numbers
var recStart = (scrollYPos / rowHeight) + 1
var recEnd = (example_data_to_example_data_items.getSize() > (recVisible + recStart - 1)) ? recVisible + recStart - 1 : example_data_to_example_data_items.getSize()


//write results to a label
elements.lbl_portal.text = "Records " + recStart + " to " + recEnd + " visible"

2- FX_divisible_check (Global boolean check)

/****
	
	Purpose			check if number is divisible	
	Input 1	 		number to act on
	Input 2			divisor	
	Returns 		true or false
	
****/

return (arguments[0]%arguments[1] == 0) ? true : false

3- FX_divisible_nearest (Global recursive)

/****
	
	Purpose			recursive fx to find the nearest divisible value
	Input 1	 		number to act on
	Input 2			divisor	
	Returns 		nearest divisible value to input 1
	Note			to track values in recursive methods you need to use a global variable
					even method defined global variables won't work as they will scope to
					current running method
	
****/

globals.fx_nearest_divisible = arguments[0]
var divisor = arguments[1]

//if not divisible keep calling self until divisible
if (!globals.FX_divisible_check(globals.fx_nearest_divisible, divisor)) {
	var remaining = globals.fx_nearest_divisible%divisor
	if (remaining < divisor/2) {
		globals.FX_divisible_nearest(globals.fx_nearest_divisible - remaining, divisor)
	}
	else {
		globals.FX_divisible_nearest(globals.fx_nearest_divisible + remaining/2, divisor)
	}
}

return globals.fx_nearest_divisible

portal.servoy (7.4 KB)

I just took a moment to check out the downloadable demo file from http://www.briandunning.com/cf/684

It looks like Filemaker 8.5 doesn’t have an event for detecting scrolling either (which I was prepared to give FM props for) – notice from the screen shot that you have to “Please click the background to refresh calculation after scrolling.” Where’s the roll-my-eyes smiley… :roll:

They also have an error in their code: if there are only say 8 records in the portal but the portal size has room for 10 records they return a numbered list of 10 instead of 8. My code accounts for this (screen shots below). Gotcha :D

So my solution is virtually identical except that I don’t write out the results as a numbered list separated by carriage returns which is a trivial matter. And I didn’t put a big button in the background to refresh the display.

In the end I have no idea what the usefulness of their code is. A live counter updating as you scroll would be cool and neither platform can do that at the moment. At least with Servoy if you really had to have something like that you could write your own Java bean with controls and throw it on a form.

Send my regards and ask them for the next challenge. :twisted:

This is great stuff, David! Good show! :D

I knew there must be some way of getting the same result with Servoy - and I’ll be sure to check out your code for using recursion in methods.

Now, off to reference this page on the other forum… :wink: :P :lol:

Just for my personal instruction and enlightenment: Why is it that we can’t get the same thing for a tabpanel again?

Thanks again,

Ben

LOGIsoft:
Just for my personal instruction and enlightenment: Why is it that we can’t get the same thing for a tabpanel again?

Portals have the functions .getScrollY() and .getScrollX() while tab panels don’t. As I remember these functions (and .setScrollX() and Y()) got added in back in the early days because someone requested them.

Probably Harjo. We called him the portal king back then. 80 of his first 100 posts were regarding portals. True story.

LOGIsoft:
Now, off to reference this page on the other forum… :wink: :P :lol:

Done!

Ben

Probably Harjo. We called him the portal king back then. 80 of his first 100 posts were regarding portals. True story.

:lol: :lol:

the good old-days! :lol: :lol:

Marcel the forum king (most posts)
Harjo the portal king
David the abstraction king

Who is next!? ;)

Roclasi the Postgress plugger king :)

I do hope I am known for a little bit more then just presenting this wonderfull thing that is PostgreSQL ;)

:D

Well, you started this thing yourself.
I guess all three you mentioned would like to be recognized for more :)

ROCLASI:
I do hope I am known for a little bit more then just presenting this wonderfull thing that is PostgreSQL ;)

:D

I would be more worried about having the word “plugger” in your esteemed title 8)

I was hoping for the beer king title myself. I doubt anyone can remember who got dubbed with that…

I was hoping for the beer king title myself. I doubt anyone can remember who got dubbed with that…

There can be only one …Arise Mr Cusick … 8)

Cheers
Harry

Harry Catharell:

I was hoping for the beer king title myself. I doubt anyone can remember who got dubbed with that…

There can be only one …Arise Mr Cusick … 8)

Cheers
Harry

Nah, we just call him Biertje Bob ;)

guys, guys! back to work now! :lol: