Send email from dataTables using select - Not a question just helping

Send email from dataTables using select - Not a question just helping

davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0
edited August 2020 in Free community support

Hey Guys,
I figured out how to easily send an email by selecting the record you want to send and clicking the email button. I thought I would share this. I use tinyMCE to make it look nice and formatted but you can use whatever you want.

    buttons:[
                        { extend: "edit", text: "Update",  editor: editor },
                        {
                    "text" : 'Email',
                    action : function(e, dt, node, conf) {
                        var data = table.buttons.exportData({
                            "stripHtml" : true,
                            "columns" : ':visible',
                            "modifier" : {
                                "selected" : true
                            }
                        });
                        console.log(data);
                        var headerArray = data.header;
                        var rowsArray = data.body;
                        var rowItem = '';
                        var innerRowItem = '';

                        for (var h = 0, hen = rowsArray.length; h < hen; h++) {
                            var innerRowsArray = rowsArray[h];

                            for (var i = 0, ien = innerRowsArray.length; i < ien; i++) {
                                var outerCount = [i];

                                var checker = 'false';
                                for (var j = 0, jen = headerArray.length; j < ien; j++) {
                                    if ( outerCount = [j] & checker == 'false') {
                                        checker = 'true';
                                        innerRowItem += headerArray[i];
                                    }
                                }

                                if (innerRowsArray[i] != '') {
                                    innerRowItem += ': ';
                                }

                                innerRowItem += innerRowsArray[i];

                                if (innerRowsArray[i] != '') {
                                    innerRowItem += '<br>';
                                }

                            };

                            innerRowItem += '<br>';

                        };
                        $('#emailForm').modal({
                            showClose : true,
                            fadeDuration : 250,
                            fadeDelay : 1.5
                        });
                                            tinymce.activeEditor.execCommand('mceInsertContent', false, innerRowItem);
                        //$("textarea#mce-content-body").val(innerRowItem);
                    }
                },
                        { extend: "remove", text: "Delete",  editor: editor },
                        { extend: 'csvHtml5',
            footer: true,
            text:   'CSV',
            filename: function(){
                       var d = new Date();
                       month = '' + (d.getMonth() + 1),
                       day = '' + d.getDate(),
                       year = d.getFullYear();
                       var n = d.getTime();
                       var now = new Date();
                       var months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
                       var formattedDate = now.getFullYear() + months[now.getMonth()] + now.getDate();
                       return formattedDate + 'RMA Submissions'}

           },
                     { extend: "pdfHtml5", text: "PDF", orientation: 'landscape', pageSize: 'LEGAL' },
                     { extend: "searchPanes", text: "Filter"},
        ],

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Excellent work! Thanks for sharing this with us.

    Allan

This discussion has been closed.