Solved

Change class of TD cell with JQuery based on Calculated Cell Values

Posted on 2013-06-09
6
253 Views
Last Modified: 2014-09-15
I have the following code that is launched in an AJAX page from SharePoint. I am trying to get the class of the td to change if the value of the calculate cell is greated than zero.

The class name to change to is "red". The table ID is "ost-SubDetailsTable"

Here is the HTML table row code:

<tr id="ost-GapRow">

			<td class="t-column" style="padding:5px;">Gap</td>
			<xsl:if test="$qTargetType = 'Field'">
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'North-East' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed:{count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'North-East' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>		
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'South' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'South' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'West' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'West' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'Mid-West' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@Sales_x0020_Force = $qFranchiseSpeaker and  @ContentType = 'Field Observations' and @CollapsedCensusRegions  = 'Mid-West' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
			</xsl:if>
			<xsl:if test="$qTargetType = 'Speaker'">
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@SpeakerBureau = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions = 'North-East' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@SpeakerBureau  = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'North-East' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@SpeakerBureau = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'South' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@SpeakerBureau  = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'South' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>		
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@SpeakerBureau = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions = 'West' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@SpeakerBureau = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'West' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
				<td class="t-columngap" style="text-align:center; padding:5px;" title="Scheduled: {count(dsQueryResponse/Rows/Row[@SpeakerBureau = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'Mid-West' and @ObservationStatus = 'Planned' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}  |  Completed: {count(dsQueryResponse/Rows/Row[@SpeakerBureau  = $qFranchiseSpeaker and  @ContentType = 'Speaker Programs' and @CollapsedCensusRegions  = 'Mid-West' and @ObservationStatus = 'Completed' and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &gt;= $qTargetStart  and ddwrt:FormatDateTime(string(@Date_x0020_of_x0020_Observation), 1033, 'yyyyMMdd') &lt;= $qTargetEnd])}"></td>
			</xsl:if>
	</tr>

Open in new window

0
Comment
Question by:aehrenwo
  • 3
  • 2
6 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39233866
Which one is the calc cell?
Which td need to be changed based on that?
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39233883
Hi,
could you please post the generated html code (result)?
Which SharePoint version/edition?
Thanks
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39234040
since change event only works with text fields, text areas and select elements, u need to use SetInterval to check whether the td value has changed and the criteria was matched (greater than zero):
setInterval(function() {			
		$('#ost-GapRow tr td').each(function (i, item) {
			if ($(item).text() > 0) {				 
				  $(item).attr('class', 'red');
			} 
		});
	}, 100);

Open in new window

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:aehrenwo
ID: 39234360
Thanks for the quick reply. How would it be modified it if I only wanted to check the row that has the final total? let's say that it's called ID "gaprow".
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39234368
setInterval(function() {			
		var td= $('#ost-GapRow tr td:last');
			if (td.text() > 0) {				 
				  td.attr('class', 'red');
			} 
		});
	}, 100);

Open in new window

0
 

Author Comment

by:aehrenwo
ID: 39238005
I have included this code on the aspx page directly but it doesn't seem to be working.

I think this may be because there is code on the main page that is referencing the aspx page using an AJAX call to display the content in a div container. Would this impact the jquery code from executing?

I basically included this as the bottom of the aspx page that has the table in it with the Gap values.


Open in new window

<script type="text/javascript">
setInterval(function() {                  
            $('#ost-GapRow tr td').each(function (i, item) {
                  if ($(item).text() > 0) {                        
                          $(item).attr('class', 'red');
                  }
            });
      }, 100);
</script>
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now