function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
imran Rahmanimran Rahman 

Clickable row in datatable

I have a datatable displaying a custom object in my visualforce page, currently I display a output link in my last column to link to the detail page for the record.
How can I make the whole row clickable to the detail page?
Best Answer chosen by imran Rahman
Amritesh SahuAmritesh Sahu
Hi Imran,

You have to use JQuery to achieve this.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $j = jQuery.noConflict();
    function clickElem(elem){
        var url =  "/" + ($j(elem).find(".Id").text());
        window.open(url,"_top");
    }
</script>

<apex:pageBlock>
<apex:pageBlockTable value="{!accounts}" var="acc" onRowClick="clickElem(this);">
            <apex:column value="{!acc.id}" styleClass="Id"/>
            <apex:column value="{!acc.name}" />
        </apex:pageBlockTable>
</apex:pageBlock>
Hope it helps you.



Thanks,
Amritesh