?
Solved

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

Posted on 2013-06-09
6
Medium Priority
?
356 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:Meir Rivkin
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:Meir Rivkin
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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:
Meir Rivkin earned 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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 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)
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…
Suggested Courses

862 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