Solved

total sum with filter inside tfoot

Posted on 2014-03-14
6
498 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
  • 2
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
hi,

Returns zero in the total row
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
I found the solution,

include another parent() to move outside the toot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now