Solved

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

Posted on 2013-06-09
6
302 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

730 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