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
MCPMCP 

Javascript on a VisualForce page

I created a controller to get all the rows of a custom object.
 
I would like to loop through this data using Javascript on my VisualForce page.
I tried it using {!customobject} where customobject is a getter on my controller.
However, it only displays the object ids of these rows. Do you know how I could access the other fields
for those rows?
 
 
Thanks in advance.
 
Sam.arjSam.arj
Can you post the code, it's hard to tell from your description what you want to achieve.

MCPMCP

Thanks for responding Sam.

Here is my code for the controller

 

public SOF_Products__c[] getSOF1(){
       sof1 = [select id, name,SOF_ID__c, Description__c,Billing_Cycle__c, Billing_Start_Date__c, Amount__c,Period__c  from SOF_Products__c where SOF_ID__c =
            :ApexPages.currentPage().getParameters().get('id')and Period__c = : 1 ];  //
       return sof1; 
   }

 

I'm trying to display the data from my controller using JavaScript in VisualForce page.


var ex2 = "{!sof1}";

document.write("{!sof1}");

 

this code in the page only shows the record IDs. I couldn't access the other fields like the name,Description__c, etc.

!sof1.Description__c does not work.

I also tried using document.getElementById but it returns null.


 

 

Sam.arjSam.arj

First off, javascript won't work the way you are using it.

Tell me what you want to achieve?

Who should have all the data on the client-side?

MCPMCP

Hi Sam.

With VF I was trying to use datatable to display the rows in my controller. However, I need to group the data based on the value on the field Period__C. This is on my post http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=5484.

Below is my original controller:

public SOF_Products__c[] getSOF(){
       sof = [select id, name,SOF_ID__c, Description__c,Billing_Cycle__c, Billing_Start_Date__c, Amount__c,Period__c  from SOF_Products__c where SOF_ID__c =
            :ApexPages.currentPage().getParameters().get('id') ];  
       return sof; 
   }

I want to display all rows with Period__c = n so I could add a header saying the Period number (Period__c) and a footer with sum of Amount__c. So what I'm trying to do is group the data by Period.

Unfortunately I couldn't find a way to do this so I tried JavaScript hoping I could use the "for" loop. But I don't know how to access the field values on my controller from within JavaScript.

Thanks again.

Sam.arjSam.arj
Perhaps you would be better of doing this in an s-control because in s-controls you have full control over rendered html.

However, if your report layout is simple I might create an internal Apex class with properties equal to exact number of columns I need in my report. Then using a method in my controller I would create my report TEXT (to be rendered by pageBlockTable, or anything else) line by line in collection (List) of my custom class.

Handing over that class to pageBlockTable you can then render it on the page.

Code:
public class mycontroller {
  public class cutomClass
  {
      public string Column1()
      {
          get {}
          set {}
      }

      public string Column2()
      {
         get{}
         set{}
      } 
  }

  public PageReference RunReport()
  {
     ...
  }   

}