Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My goal is to replace a text in a specific column by an icon using only javascript.

function ReplaceTxtbyIcn(targetWP, targetColumn, pat, urlname)
{
  var table = document.getElementById(targetWP);
  if (table != null)
     {
      var tbody = table.childNodes[0];
      var trs = tbody.childNodes;
      for (var i=1;i<trs.length;i++)
      { 
        var tdVal = trs[i].childNodes[targetColumn].outerText;
        if( tdVal == pat)
       {
         $(trs[i].childNodes[targetColumn]).text('');
         $(trs[i].childNodes[targetColumn]).append('<img src="******SomeURL******'+urlname+'.png"  alt="'+pat+'"/>');
       }    
     }
    }
};

For targetWP it should be equal to ctx.listName + "-" + ctx.view My problem here is how to get the ctx for the specific webpart using the id of the webpart. I am on Sharepoint 2007, any help ?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The following function could be used for retrieving Context Info by Web Part ID

//Retrieve Context Info By WebPartID
function getContextInfo(webPartID)
{
        //Resolve ViewId from WebPartId
        var strViewId=webPartID.toUpperCase();
        //Retrieve Context Info Number
        var ctxNum=g_ViewIdToViewCounterMap[strViewId]; 
        if (ctxNum==null)
            return null;
        //Retrieve Client Context by Number  
        var ctxT=window["ctx"+ctxNum];
        return ctxT;
} 

Usage

//Retrieve Context Info for Latest Documents Web Part 
function loadLatestDocumentsContextInfo()
{ 
    var curctx = getContextInfo('{d8e2098c-170d-4114-92f1-95619f716911}');
    console.log(curctx);
}


_spBodyOnLoadFunctionNames.push('loadLatestDocumentsContextInfo');

Note: Web Part ID could be identified on page as specified here

share|improve this answer
    
Tested with SharePoint 2010 only –  Vadim Gremyachev Jan 2 '13 at 21:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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