Temporary disable server processing on table

Temporary disable server processing on table

gtuxgtux Posts: 2Questions: 1Answers: 0

I have a datatable loaded by server side data, everything is ok with this. Now, I want to update the data rows by listen notifications from AWS SQS, when I get a new row data and added to table API and then call the "draw" method, the API trigger an ajax refresh from server side instead (the table was setup with server procesing).

There is a way to "disable" ajax calls temporary? Because, I don't want disable for all time, I want server side processing for pagination and search, only want to add my new row without call the server.

I try this:

        // Get the API object
        var table = $('#tblModel').DataTable();

        // Initialize the Amazon Cognito credentials provider
        AWS.config.region = 'us-west-2'; // Region

        /**
         * Gets the user's Identity
         */
        $.getJSON("/cognito", function(data) {
            if (data) {
                IdentityId = data.IdentityId;

                AWS.config.credentials = new AWS.CognitoIdentityCredentials({
                    IdentityPoolId: IdentityPoolId,
                    IdentityId: data.IdentityId,
                    Logins: {
                        "cognito-identity.amazonaws.com": data.Token
                    }
                });
                
                var queue = new AWS.SQS({params: {QueueUrl: QueueUrl, WaitTimeSeconds: 20}}); // using url to queue
                getMessages(queue);
            }
        });
        
        /**
         * Gets the message from SQS
         */
        function getMessages(queue) {
            queue.receiveMessage(function (err, data) {
                if (data) {
                    if (data.Messages.length == 0) return;
                    try {
                        // here add a row or rows, but it trigger a call to refresh data from server side instead.
                        if (data.Messages.length > 1)
                            table.rows.add(data.Messages.map(transformMessage)).draw();
                        else 
                            table.row.add(transformMessage(data.Messages[0])).draw();
                        
                        // now delete the messages
                        queue.deleteMessageBatch({
                            QueueUrl: QueueUrl,
                            Entries: data.Messages.map(function(Message) {
                                return {
                                    Id: Message.MessageId,
                                    ReceiptHandle: Message.ReceiptHandle
                                };
                            })
                        }, function(err, data) {
                            if (err) console.error(err);
                        });

                        getMessages(queue);
                    } catch (e) {
                        console.error(e);
                    }
                }
            });
        }
        
This discussion has been closed.