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
naveen reddy 19naveen reddy 19 

Unable to dynamically construct data table in visualforce using jquery/javascript

Hi All,

  Trying to construct the data table dynamically using visualforce remoting with jquery data table.
Getting the table with empty values.
The following is the code and output. Please help me in getting this done. 
<apex:page controller="AccountRemoter"  sidebar="false"  docType="html-5.0" >
        <link rel="stylesheet" href=""/>
        <apex:includeScript value="{!$Resource.Jquery2}"/>
        <script src=""></script>
        <script type="text/javascript">
            $ = jQuery.noConflict();
        function getRemoteAccount() {
                function(result, event){
                    $('#example').DataTable( {
                        data: result,
                        columns: [
                            { title: "Id" },
                            { title: "Name" }
                    } );
                {escape: true}
        <button onclick="getRemoteAccount()">Get Account</button>
        <table id="example" class="display" cellspacing="0" width="100%">
global with sharing class AccountRemoter {

    public String accountName { get; set; }
    public static Account account { get; set; }
    public AccountRemoter() { } // empty constructor
    global static List<Account> getAccounts( ) {
        List<Account> accnts= [SELECT Id, Name 
                   FROM Account  limit 5];
        return accnts;

Output with empty data

Any help is really appreaciated . Thanks in advance.

Alvaro CollazoAlvaro Collazo
Did you fix it finally?
Harpreet On CloudHarpreet On Cloud
Refer to these links
Further Advanced:

Data tables examples:
Ajay K DubediAjay K Dubedi
In this code, you want to use Ajax property but it is not possible to create dynamic datatable like this in JQuery.if you use Ajax then your data table will show your data.
you should iterate the result value and put it into each column you want.

you can go with the link-

I hope you find the solution helpful. If it does, please mark as Best Answer to help others too.
Ajay Dubedi