Table load by server side and then updated by push data

Table load by server side and then updated by push data

gtuxgtux Posts: 2Questions: 1Answers: 0
edited November 2016 in Free community support

I have a datatable loaded by server side data, everything is ok. Now, I want to update the data by listen notifications on AWS SQS, when I get a new row data, I try this:

        // 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);
                    }
                }
            });
        }
        

But as the table was setup by server procesing, every time that I call draw the table call the ajax data instead to use the new row(s) added.

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

This discussion has been closed.