I have a requirment to display child object records using jquery datatable in each child object jquery tab when a parent is selected.Currently i am using remote action to display all the child records in datatables.Is there any other way to get the rows from controller up on initial page loads.

For Example object A is parent where as object B and object c are linked to A using junction objects.In a visualforce page, on left side of the page object A names are displayed as menu, in center of page multi tabs are shown to switch between object B and C tabels.Initailly, page loads with object A values and object B, C rows in data tables.

Getting Error when using fnserverData function in data table.

"fnServerData": function(sSource, aoData, fnCallback) {   

    for (var i = 0; i < jsonForChildrenA.length; i++) {

        var r = jsonForChildrenA[i].Account__r;
        for(var j = 0; j < accFields.length; j++) {
           var field = accFields[j];
           if (r[field] == undefined) {
                DataTables pops a dialog for undefined values
                r[field] = null;

Its not too clear from your question about what problem you are trying to address, but here are two other ways to get the rows from the controller when the page initially loads. (This assumes you are using DataTables.)

1. Normal Visualforce

You can start with a normal apex:pageBlockTable and just add DataTable to it to add the client-side behaviour:

<apex:pageBlockTable value="{!childrenA}" var="c" styleClass="dataTable">

var j$ = jQuery.noConflict();

A more detailed example is shown here.

2. Render JSON into the page

You can render the initial JSON into the page by having the controller generate JSON:

public String jsonForChildrenA {
    get {
        return JSON.serializePretty(childrenA);

and then assigning it somewhere in the JavaScript in the page:

var jsonForChildrenA = {!jsonForChildrenA};

and then the DataTables fnServerData JavaScript function can just reference that.

| improve this answer | |
  • sorry for the confusion i have edited my previous post with an example. can you provide me a sample code using fnserverData function to get better understanding. – vraavi May 19 '14 at 19:30
  • @vraavi Here is its generic use force201.wordpress.com/2014/03/15/…. – Keith C May 19 '14 at 20:15
  • i tried adding rows to table using jsonForChildrenA variable from fnServerData i was getting javascript error something like "oadata length is not defined." – vraavi May 21 '14 at 14:34
  • 1
    @vraavi If you are going to do client-side JavaScript you need to read up on JavaScript and get familiar with your browser's "Developer Tools". These include a full debugger with breakpoints so they are better than the tools Salesforce provides for Apex - you just need to invest time in learning about them. – Keith C May 21 '14 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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