load data table app script code example

Example 1: load data table app script

<script type='text/javascript'>
    $(document).ready(function(){
        var runner = google.script.run.withFailureHandler(onFailure);
        runner.withSuccessHandler(onSuccess).getData();
    });
    var onSuccess = function(data){
        var aDataSet = data.slice(1);  // all except header


        var head = [];  // headers
        data[0].forEach(function(e){
            head.push({'sTitle': e});
        });

        $('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
        $('#example').dataTable( {
            "aaData": aDataSet,
            "aoColumns": head
        });
    }
    var onFailure = function(err){
        alert(err.message);
    }
    </script>

Example 2: load data table app script

function getData(){
   var data = SpreadsheetApp.openById('YourSheetID').getSheetByName('YourSheetName').getDataRange().getValues();
   return data;
}