I have the following JQuery code entered into a content editor web part which does some conditional formatting on the table cell of a list. The trouble with this is that it executes fine on document ready but when the user clicks a "next" image on the pagination area or clicks a column header to sort the list the page is not actually reloading so the formatting does not work. What is the best way to insure any click even on the list table would execute the formatting?

$(document).ready(function () {
$('tbody td.ms-vb2:contains("Green")').css("background-color", "green").css("color", "white");

$('tbody td.ms-vb2:contains("Yellow")').css("background-color", "Yellow").css("color", "Black");   

$('tbody td.ms-vb2:contains("Red")').css("background-color", "Red").css("color", "White");   

Another way to do this is to modify the XSLT and do your formatting there. Then you wouldn't need the jQuery dependency.

|improve this answer|||||
  • 1
    I'd do this unless SPD is off limits (and thus the need for a jQuery solution). – Eric Alexander Jun 21 '12 at 16:55
  • I am thinking i need jquery here because the users change the columns a lot. I have it working mostly now. However it only works on the first click . The second click does not execute my code for still unknown reasons. – ChiliYago Jun 21 '12 at 20:25
  • Right, I understand the issue, I was just providing an alternate solution where you don't have to worry about the update panel postbacks and executing your JS. If you modify the xslt, you can change the actual html on the page. No JS needed. – Steve Lineberry Jun 22 '12 at 0:35

I would suggest trying to determine what JS event is being called when the page refreshes and doing a double delegate on that function to run your code.

I've never used it before but I've heard other's having good success using eventbug for firefox to try to find these type of JS events.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.