Set CSS value on DispForm based on list item ID

Home Forums Classic DFFS Set CSS value on DispForm based on list item ID

Viewing 3 reply threads
  • Author
    Posts
    • #9201
      Bloodlvst
      Participant

        Hey again!

        So we have a few specific articles in one of our lists that require specific formatting for tables when displayed. In doing some testing, I think I may be on the right track, but not quite there.

        What I’m trying to do is make it so if the item ID is equal to ID’s 26, 30, or 31, that I inject the CSS via jQuery to format the table in those articles the way we wish. Here’s what I’ve managed to come up with, but it still doesn’t work. I’m not very experienced in JavaScript/jQuery so I’m likely missing something.

        var itemID = "?ID=26";
        $(function(){
        if (location.search == itemID){
        	$(".ms-rteTableHeaderEvenCol-default, .ms-rteTableHeaderOddCol-default").css("color", "#FFF !important");
        	}
        });

        Can anyone help me figure out what I’m missing?

        Thanks!

        • This topic was modified 9 years, 1 month ago by Bloodlvst.
      • #9212
        Alexander Bautz
        Keymaster

          Hi,
          You can put this in the Custom JS section in DFFS backend. It adds a style tag to the page with the override CSS code.

          var cssBuffer = [];
          switch(spjs.dffs.data.thisItemID){
          	case "26":
          		cssBuffer.push(".ms-rteTableHeaderEvenCol-default, .ms-rteTableHeaderOddCol-default{")
          			cssBuffer.push("color:#fff!important;");
          		cssBuffer.push("}");
          	break;
          	case "30":
          		// add the style like the previous "case"
          	break;
          }
          $("body").append("<style type='text/css'>"+cssBuffer.join("")+"</style>");

          Let me know how this works out.

          Alexander

        • #9226
          Bloodlvst
          Participant

            As always, thanks Alex!

            This works exactly like I need it to! Now those 3 articles will have their special formatting when being displayed and still be easy to edit for our novice users 🙂

            How much is a beer in Norway? I owe you several at this point.

          • #9231
            Alexander Bautz
            Keymaster

              I’m glad it worked out.

              A good beer in the local grocery store is about $5 – so Norway is not the place you go for cheap beer!

              Best regards,
              Alexander

          Viewing 3 reply threads
          • You must be logged in to reply to this topic.