0

How can I "read" the fields of an hidden column with JavaScript?

More precisely, I would like to recolor columnA fields according to columnB "Priority" fields (which is hidden in forms and not displayed in view).

I'm using MOSS and JavaScript.

I can recolor my fields, but I can't find a way to access to this "Priority" column since it's not displayed in my list (I can't manipulate it into the DOM), it is just a choice value (high, low ...) set to the item and hidden in my views/forms (for visibility, since I want use color thanks to this "priority" value).

Thank you for the eventual help.

2 Answers 2

1

If you're using pure javascript, the easiest way is to add the field back to your page, hide it with a css style or some other javascript, then read the field value directly.

If you need, you can edit the Dataview Webpart in designer to give the tds in that particular column a special class or something to make it easier to select.

3
  • Is it "safe" to hide a column and its fields with JavaScript? Instead of just not display it in the view. What about the performance level?
    – Funnybear
    Commented Jul 17, 2014 at 14:42
  • No it's not generally safe :) an enterprising user could read the data from the page source -- this is a downfall of most purely client side approaches though. This approach is not as performant as using conditional formatting from inside designer, which will read the list xml and do the formatting (even if the column is hidden) and the reason is simply because it needs to draw data you then hide from the user.
    – John-M
    Commented Jul 17, 2014 at 15:49
  • 1
    I would also say the performance hit won't be too much for 1 column with a simple text status though -- so that shouldn't be too big of a concern, and honestly if you're coloring the columns based on the data you're already telling people what the status is, so if someone opens the page source to read it, it shouldn't matter - but that's just what I think
    – John-M
    Commented Jul 17, 2014 at 15:57
1

I would use the CodePlex SPSERVICES project (http://spservices.codeplex.com/), which is compatible with SharePoint 2007.

SPServices is a jQuery library which abstracts SharePoint's Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.

There is an example on the following page that shows you how to query a list:

http://spservices.codeplex.com/wikipage?title=GetListItems&referringTitle=Lists

I modified the example from the previous page to address your questions more specifically:

script type="text/javascript" src="filelink/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="filelink/jquery.SPServices-0.6.2.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Priority' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var currentItemId = $(this).attr("ows_ID");
        var currentItemTitle =  $(this).attr("ows_Title");
        var currentItemPriority =  $(this).attr("ows_Priority");
        //TODO: Find the item on the page and change the color
      });
    }
  });
});
</script>

For help with CAML queries, I recommend the SharePoint CAML Query Helper for 2007, 2010, and 2013 (http://spcamlqueryhelper.codeplex.com/).

1
  • I forgot to mention that I have limited access, I'm just an intern working on a collaborative web portal. I used @John-o answer, I simply displayed my column in order to do the recolor, then I will hide it (or not depending to my managers) with JavaScript.
    – Funnybear
    Commented Jul 17, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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