Page 1 of 1

grid onscroll

Posted: Tue Nov 08, 2016 6:54 pm
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

Re: grid onscroll

Posted: Tue Nov 08, 2016 7:00 pm
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.

Re: grid onscroll

Posted: Wed Nov 09, 2016 10:43 am
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.......... 

Re: grid onscroll

Posted: Wed Nov 09, 2016 2:32 pm
by Scott Klement
That seems like a reasonable workaround to me.

Re: grid onscroll

Posted: Wed Nov 09, 2016 3:50 pm
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);
}