Calculate number of 'pages' in table


I have an HTML page that includes a table that's populated using a script that Rainer Jeschor created for me (it basically takes the total number of rows in a CSV file and divides by 10, then displays a table on the page, 10 items at a time, and scrolls to a new 'page' every 10 seconds (and continues to loop through the table).  

It works great -- the table is populated, and scrolls through each 'row' of data in the text file, but I've noticed one issue -- if there are exactly 10 rows of data to be displayed, an extra 'blank page' is displayed -- so, instead of displaying just the 10 rows, it displays the 10 rows, then displays a 'blank page' for 10 seconds (in a loop).  

If there are over 10 rows, it works fine -- if there are 9 or less items, it works fine...  But if there are exactly 10 rows, it adds an extra 'blank page'.  

I've tried modifying items under "calculate max paging number" to try to fix this -- but haven't been able to resolve the issue.  

I'm thinking there's something in 'calculate max paging number' that can be modified to eliminate the 'extra page' if there's exactly 10 rows to display...  

Any help would be appreciated.  Thank you,


			// Global variables
			var listOfMeetings = [];
			var pagePageSize = 1;
			var currentIndex = 0;
			var tableTimer = null;

			$(function(){ // Call when html is done loading
				$.ajax({ //Your url will be filename.csv or folder/filename.csv
					method: "get",
					url: "meetingtable.csv"
				.done(function( data ) {
					var today = moment().format("YYYY-MM-DD");
					var lines = data.split("\r\n"); // split on line break
					$.each(lines,function(i){     // loop through each line
						var rowdata = lines[i].split(",");    // assign the row a variable and build array
							Name: rowdata[0],
							StartDT: moment(moment(today + " " + rowdata[1],"YYYY-MM-DD H:mm")),
							EndDT: moment(moment(today + " " + rowdata[2],"YYYY-MM-DD H:mm"))
					tableTimer = setInterval(function () {RebuildTable();}, 10000);
			function RebuildTable() {
				// Hide the table
				// Container getting remaining meetings
				var currentListOfMeetings = [];
				// Verify each entry
				$.each(listOfMeetings,function(index, element) {
					if (moment(element.EndDT) >= moment()) {
				// Calculate max paging number
				pageSize = Math.floor(currentListOfMeetings.length/10) + 1;
				if(pageSize == 1 || pageSize <= (currentIndex + 1)) {
					currentIndex = 0;
				} else {
					currentIndex += 1;
				// Reset tbody content
				// Rebuild rows
				$.each(currentListOfMeetings.slice(currentIndex*10,(currentIndex*10)+10),function(index, element) {
				// Show the table

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hans LangerCommented:
Try this to calculate your total pages:

pageSize =  Math.floor(currentListOfMeetings.length/10) + ( (currentListOfMeetings.length%10==0)?0:1 );

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
damoncf1234Author Commented:

Excellent - that works perfectly.  

Thank you,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.