grid onscroll

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
shuffman
Profound User
Posts: 22
Joined: Fri Jan 29, 2016 11:15 am
First Name: sam
Last Name: huffman
Company Name: gmdsolutions
Phone: 7122624520
Address 1: 2311 W 18th ST
City: Spencer
State / Province: Iowa
Zip / Postal Code: 51301
Country: United States
Contact:

grid onscroll

Post by shuffman »

i have a function call in the onscroll event of a grid. It seems to fire when the user hits page down as well as clicking the next page link. Is this normal behavior? I didn't think it did this in the last version. We're running pui 5.6
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: grid onscroll

Post by Scott Klement »

Are you using a scrollbar? If so, onscroll should fire anytime the scrollbar changes. In my experience, it can fire a lot of times, so you should be ready to handle the routine being called repeatedly.

If you don't have a scrollbar at all (scrollbar property is "none") then onscroll should not fire for page up or page down.
shuffman
Profound User
Posts: 22
Joined: Fri Jan 29, 2016 11:15 am
First Name: sam
Last Name: huffman
Company Name: gmdsolutions
Phone: 7122624520
Address 1: 2311 W 18th ST
City: Spencer
State / Province: Iowa
Zip / Postal Code: 51301
Country: United States
Contact:

Re: grid onscroll

Post by shuffman »

Thanks for the info. I'd prefer if the onscroll only occured if the user actually interacted with the scrollbar but i guess that may not always make sense.

Anyways, i found a workaround for my problem. Basically i didn't want the onscroll event to occur when the user presses page down or clicks the next page link. The idea here is to see if the last record in the subfile is visible when the user scrolls down which will trigger going to the next page minus a record. the onpagedown event seems to occur before the onscroll so i set a global variable temporarily to tell the onscroll event when it runs immediately afterwards to return. This seems like a pretty poor programming practice but it does work. I'm definitely open to suggestions.

Code: Select all

var noNext = false;

function checkForLast(event,subfile,option){
	try{
		if(event.currentTarget.classList.contains("paging-link") || event.key == "PageDown"){
			noNext = true;
			setTimeout(function(){noNext = false;},100);
			return;
		}
	}catch(err){}
	
	if(noNext == true){
		return;
	}
	
	The code that actually does something.......... 
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: grid onscroll

Post by Scott Klement »

That seems like a reasonable workaround to me.
shuffman
Profound User
Posts: 22
Joined: Fri Jan 29, 2016 11:15 am
First Name: sam
Last Name: huffman
Company Name: gmdsolutions
Phone: 7122624520
Address 1: 2311 W 18th ST
City: Spencer
State / Province: Iowa
Zip / Postal Code: 51301
Country: United States
Contact:

Re: grid onscroll

Post by shuffman »

ok, i'll go with it.

here is the complete function if anyone is interested.

call it from the onscroll event and onpagedown event of the grid
leave parm1 as event, parm2 is the id of the grid, parm3 needs to be the id of any field in the grid.

checkForLast(event,"SCRNS01","#SEL1");

Code: Select all

var noNext = false;

function checkForLast(event,subfile,option){
	try{
		if(event.currentTarget.classList.contains("paging-link") || event.key == "PageDown"){
			noNext = true;
			setTimeout(function(){noNext = false;},100);
			return;
		}
	}catch(err){}
	
	if(noNext == true){
		return;
	}
	
	setTimeout(function(){
		
		var subfileObj = getObj(subfile);
		
		//ignore sortable subfile
		var sortable = subfileObj.pui.properties['sortable columns'];
		if(sortable == 'true'){
			return;	
		}
		
		var pageControls = document.getElementsByClassName("paging-link");
		var recordCount = subfileObj.grid.getRecordCount();

		var lastRow = document.getElementById(option + '.' + (recordCount));
		var lastPage = false;

		if(lastRow != null && lastRow != undefined){
			lastPage = true;	
		}else{
			return;
		}
		
		for(var loopy = 0; loopy < pageControls.length; loopy++){
			if(pageControls[loopy].textContent == 'Previous'){
				var previous = pageControls[loopy];
			}
			if(pageControls[loopy].textContent == 'Next'){
				var next = pageControls[loopy];
			}	
		}
		if(lastPage == true){
			setTimeout(function(){
				next.click();
				//subfileObj.grid.scrollToRow((recordCount-2));
			},0);
		}
	},0);
}
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests