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
Rajesh_SFGRajesh_SFG 

How to Display Values from Ajax toolkit script to Visualforce Components?

Hi all,

   I retrived some values from Account object using Ajax toolkit scripts. so i able to display those values only the HTML controls like <div>, <b>. but i need to display those values in Visualforce components like datatable or datalist. Is this possible in ajax toolkit.

 

 

Thanks in advance

sfdcfoxsfdcfox

You can style the elements yourself so that they look and feel like normal components. Alternatively, you can assign an ID to the element and use that ID to pick up the element and modify it. Use $Component to reference the element. Required attributes will still be required to render the element, so you may need a "dummy" function to populate the table or list with an initially blank value.

 

For example:

 

<!-- snip -->

<script type="text/javascript">
//<![CDATA[

// On the appropriate event, call:
// sforce.connection.*some-function*
//         (*parameter1*, { onSuccess: updateTable, onFailure: alert } )

// This function receives the results of *some-function*,
// and renders the table.
function updateTable(data) {
    var myDataTable = document.getElementById('{!$Component.myDataTable}')
    // DO something with myDataTable
}
//]]>
</script>

<!-- snip -->

<apex:dataTable id="myDataTable" value="{!blankList}" var="item">
<apex:column headerValue="Field 1"/>
<apex:column headerValue="Field 2"/>
</apex:dataTable>

<!-- snip -->

The real question may be... why would you go through this much trouble? It would seem to me that you could just push the data in to the dataTable directly and save the hassle of this design. You can even use server event-generating tags (such as commandButton and actionFunction) to re-render (using the reRender attribute) to perform the same function with nearly the same efficiency. Alternatively, you could use @RemoteAction to acheive the same results with less code.