Wednesday, 1 July 2015

How to Customize Standard Related List using Visual force Page

Embed the visualforce page in  Account and click on the button to see the  changes

<apex:page standardcontroller="Account"  tabstyle="Account" sidebar="false" >
<div id="relatedlist">
<apex:relatedList id="accountlist" list="Account_related_list__r" />

</div>
<input type="button"  value="click" onclick="change();"/>
<script>

function makemaster()
{


alert('called');
}
function change()
{


var  btn=document.getElementById("relatedlist").getElementsByClassName('btn')[0];
alert(btn);
var values=btn.getAttribute('onclick');

alert(values);
console.log(values);
values=values.split(',');

alert(values);
console.log(values);
var url=values[0];
url=url.split('navigateToUrl(');
console.log(url)
//window.top.location.href =url[0];
//btn.setAttribute('onclick',values[0]+',\''+'_parent'+'\');')
btn.setAttribute('onclick','window.top.location.href ='+url[1]+';');
var values=btn.getAttribute('onclick');
console.log(values);

btn=document.getElementById("relatedlist").getElementsByClassName('btn')[1];
alert(btn);
values=btn.getAttribute('onclick');
console.log(values);

btn.setAttribute('onclick','makemaster();');

var table=document.getElementById("relatedlist").getElementsByClassName('list')[0];
alert(table);





var rows = table.rows, rowcount = rows.length, r;
alert(rowcount);
var cells,cellcount,cell;

var anchor,at;
for ( r=0;r<rowcount;r++)
{

if(r==0)
{
var x = rows[r].insertCell(0);
x.innerHTML = "Master CXPeople";
}
else
{
var x = rows[r].insertCell(0);
x.innerHTML = "<input type='radio' value='test' name='test'/>";
}

cells = rows[r].cells;
cellcount = cells.length;
alert('cell count'+cellcount);
for( c=0; c<cellcount; c++)
{  var anchors = rows[r].cells[c].getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_parent');
}

}

/*cells = rows[r].cells;
cellcount = cells.length;
alert('cell count'+cellcount);
for( c=0; c<cellcount; c++) {
cell = cells[2];
cell=cells[2].innerHTML;
alert(cell);
var a=cells[2].childNodes.length;
//var cell =cell.getAttribute("href");
alert('child nodes'+a);
var a=cells[2].children.length;
alert('children'+a);
a=cells[2].children[0].href="https://www.google.com";
cells[2].innerHTML="<input type='radio' value='test' name='test'/>";
// now do something.
}*/

}
var anchors = document.getElementById("relatedlist").getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_parent');
}
}


</script>



</apex:page>

No comments:

Post a Comment