1
<apex:page showHeader="false">
    <script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
    </script>
    <script src="../../soap/ajax/37.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload = setupPage;
        function setupPage() {
            var state = { //state that you need when the callback is called
                output: document.getElementById("output"),
                startTime: new Date().getTime()
            };
            var callback = {
                onSuccess: layoutResults,
                onFailure: queryFailed,
                source: state
            };
            sforce.connection.query(
                "Select Name,Id from User",
                callback);
        }
        function queryFailed(error, source) {
            source.output.innerHTML = "An error has occurred: " + error;
        }
        function layoutResults(queryResult, source) {
            if (queryResult.size > 0) {
                var output = "";
                var records = queryResult.getArray('records');
                for (var i = 0; i < records.length; i++) {
                    var user = records[i];
                    output += user.Id + " " + user.Name +
                        "<br>";
                }
                source.output.innerHTML = output;
            }
        }
    </script>
    <div id="output"> </div>
    <html>
    <table>
        <tr>
            <td>
                <div id="output"> </div>
            </td>
        </tr>
    </table>
    </html>
</apex:page>

how the data in tabular format,please suggest me how to do it,,,thanks in advance.

0

1 Answer 1

3

You better dynamically create a new tr element and add information (Id,Name) to is as columns (td). Then append the whole tr you the table:

function layoutResults(queryResult, source) {
    if (queryResult.size > 0) {
        var records = queryResult.getArray('records');
        for (var i = 0; i < records.length; i++) {
            var user = records[i];

            var tr = document.createElement("tr");
            tr.innerHTML = '<td>' + user.Id + '</td>' + '<td>' + user.Name + '</td>';
            document.getElementById("myTable").appendChild(tr);         
        }
        source.output.innerHTML = output;
    }
}


<div id="output"></div>

<table id="myTable">
    <!-- Header -->
    <tr>
        <td> Id </td>
        <td> Name </td>
    </tr>
</table>
4
  • can u explain more,,,iam not getting what you are telling now.
    – Satya
    Commented Jun 30, 2016 at 7:44
  • You should take every record and add it as row (tr) element to the table using appendChild() method. Commented Jun 30, 2016 at 7:45
  • thanks,working.cant we use pageBlocktable here?!please help
    – Satya
    Commented Jun 30, 2016 at 7:48
  • No we can't. PageBlockTable is an Visualforce tag, not a HTML tag. It work only with merge variables. In your case you are using an Javascript remoting without merge variables. Commented Jun 30, 2016 at 7:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .