Link to home
Start Free TrialLog in
Avatar of Adam Ehrenworth
Adam EhrenworthFlag for United States of America

asked on

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

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

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Which one is the calc cell?
Which td need to be changed based on that?
Hi,
could you please post the generated html code (result)?
Which SharePoint version/edition?
Thanks
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

Avatar of Adam Ehrenworth

ASKER

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".
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>