Converting from Remote Objects to RemoteAction (Javascript, VisualForce, Apex)

Converting from Remote Objects to RemoteAction (Javascript, VisualForce, Apex)

vshakevshake Posts: 2Questions: 2Answers: 0

Hi,

I currently have a functioning Datatable that leverages Remote Objects to populate itself. The following is the shell code for the table:

    j$ = jQuery.noConflict();
    j$(document).ready( function () {
        var invoiceTable = j$('[id$="invoicetable"]').DataTable({
            "language": {
            "loadingRecords": "",
            "emptyTable": "No data available"
             },

            // Use the Remote Object retrieve method to get a list of Invoice Payments associated with the Order in question.
            "ajax": function(data, callback, settings) {
                var invoiceData = new SObjectModel.CW_Invoice__x(); //might need offset on limit
                invoiceData.retrieve({where: {Order_Number__c: {eq: "{!OrderNumber}"}}, limit: 100}, function(err, records){       
                    if(err) alert(err.message);

                    else if (records.length != 0){

                                    //process records into dataItems

                            callback({'data': dataItems});      
                            };

                        });                                                             
            },

            // Specify our columns. The first column is used to control expanding and collapsing.
            "columns": [
                { "class": 'details-control',
                    "orderable": false,
                    "data": null,
                    "defaultContent": '',
                    width: "8%",
                    },                  

                {"data": "_props.Invoice_Date__c",
                    "defaultContent": '' },
                {sClass: "alignRight", "data": ".attribA",
                    "defaultContent": '' },
                {sClass: "alignRight", "data": ".attribB",
                    "defaultContent": '' },
                {sClass: "alignRight", "data": ".attribC",
                    "defaultContent": '' },                             
                ],
            order: [[1, 'asc']],
        } );

... code to handle expanding and collapsing, etc.

Unfortunately I need to bring back more than 100 rows so I want to use a server side @RemoteAction method in the controller to return me all records. The following test code in my VisualForce page successfully pulls back the relevant data in javascript friendly format:

function getInvItems(OrderNumberString){
Order_BillingIntCtrlExt.getInvoiceItems(OrderNumberString,handleInvoiceItems);
}
function handleInvoiceItems(result, event) {
if(event.type == 'exception') {
alert(event.message);
} else {
alert(result.length);
result;
}
};

My question is:

How do I update the Datatable code to work with the results sent back from the @RemoteAction method as opposed to the Remote Object?

This discussion has been closed.