?
Solved

total sum with filter inside tfoot

Posted on 2014-03-14
6
Medium Priority
?
568 Views
Last Modified: 2014-06-01
Hi,

I am using the following code to make column sum in the final row of my table:

$("#tblHitParade tr:last td:not(:first,:last)").text(function(i){
	if (i == 0  || i == 8 || i==10 || i==12 || i==14){}else if(i==1){return "Totales:";}else{
    var t = 0;
    $(this).parent().prevAll().find("td:nth-child("+(i+2)+")").each(function(){
        t += parseInt( $(this).text(), 10 ) || 0;
    });
    return t;}
});

Open in new window


This code works perfect, but I am having a problem:

I am using tablesorter and when i make a filter or sort, then it takes in consideration my total row, i create a tfoot for the total row, and then the tablesorter works well, but the total row loss his sum functionality, how i can modify the code for the sum to work on the total row inside my new tfoot tag and actualize when filter the table to update the row total values?
0
Comment
Question by:joyacv2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39929406
Try the following :

$("#tblHitParade tr:last td:not(:first,:last)").text(function(i){
	/*if (i == 0  || i == 8 || i==10 || i==12 || i==14){

	}
	else*/
	if(i==1) {
		return "Totales:";
	}
	else {
		var t = 0;
		$(this).filter(function() { 
			var isNotInsideTFOOT = $(this).closest("tfoot").length==0; // true or false
			return isNotInsideTFOOT; // http://api.jquery.com/filter/
		}).parent().prevAll().find("td:nth-child("+(i+2)+")").each(function(){
			t += $(this).text() * 1;
		});
		return t;
	}
});

Open in new window

0
 
LVL 1

Author Comment

by:joyacv2
ID: 39929421
hi,

Returns zero in the total row
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39929489
could you do a right click on the table, choose inspect element, locate the table tag, right click on it, and choose "copy html" to post it here, thanks.
0
 
LVL 1

Accepted Solution

by:
joyacv2 earned 0 total points
ID: 39929723
I found the solution,

include another parent() to move outside the toot
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question