Error on dataTables
Error on dataTables
I'm having this error on my html table :<
"DataTables warning: table id=data-table2 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4"
Here's my html code, javascript and my code on code.gs.
I created a website using google app script and the data being display on my html table came from my google sheet.
<div class="containerzxc">
<h3><b style="color:teal;text-transform:uppercase">Rooniverse</b></h3>
<table id="data-table1" class="table table-striped table-sm table-hover table-bordered" ></table> <br>
</div>
Javascript code:
```
google.script.run.withSuccessHandler(showData1).getData1();
function showData1(dataArray){
$(document).ready(function(){
$('#data-table1').DataTable({
data: dataArray,
columns: [
{"title":"Name"},
{"title":"Date"},
{"title":"Email Address"},
{"title":"ID"},
{"title":"Ownership Group / Brands"},
{"title":"Approved/Rejected"},
{"title":"Rejected Reason"},
{"title":"Additional Notes"},
{"title":"Segment"},
{"title":"SMB"},
{"title":"MM"},
{"title":"KAM"},
{"title":"DOG"}
]
});
});
} ```
Code.gs:
``` //GET DATA FROM GOOGLE SHEET AND RETURN AS AN ARRAY
function getData(){
var spreadSheetId = "1mHdXoizZYhskhH-8wJhf7ZjrsTNC3oxXTYdnxbntBoY"; //CHANGE
var dataRange = "Homepage!A2:D"; //CHANGE
var range = Sheets.Spreadsheets.Values.get(spreadSheetId,dataRange);
var values = range.values;
return values;
} ```
Please help as I've been searching for a solution for it :< Also, is it possible when a data is pasted on the google sheet the html table will update automatically without refreshing the whole page and is it also possible that the background for the new data will change to "red" so I can easily see that there's a new data pasted on the google sheets.
Thank you so much! :'<
Answers
The error suggests that
dataArray
does not contain an array of arrays, but rather an array of objects. See this section of the manual for details on the difference between them.If that doesn't help, please show us what
dataArray
contains.You can use the DataTables API to update the table dynamically without reloading the page. As long as you get some notification when the data changes, then yes you can do that.
Add a class to the row after you've added it via the API.
Allan