Currently, I'm trying to pull the filtered district data from my table and submit it to a column in my google sheets. I'm able to manually input data directly into my google sheets, but I can't figure out how to pull the data I've filtered in my data and input it into the sheets.
function onSuccess() {
alert('Your request has ben submitted');
}
function buttonFunction() {
var table = document.getElementById("myTable");
var rows = table.getElementsByTagName("tr");
var cells = rows.getElementsByTagName("td");
var cellvalue = (cells[0].innerText);
google.script.run.withSuccessHandler(onSuccess).setValue(cellvalue);
}
function generateTable(dataArray) {
var tbody = document.getElementById("table-body");
var counter = 0;
for (var row in dataArray) {
var row = document.createElement("tr");
var col1 = document.createElement("td");
var col2 = document.createElement("td");
var col3 = document.createElement("td");
var col4 = document.createElement("td");
var col5 = document.createElement("td");
var col6 = document.createElement("td");
col1.textContent = dataArray[counter][0];
col2.textContent = dataArray[counter][1];
col3.textContent = dataArray[counter][2];
col4.textContent = dataArray[counter][3];
col5.textContent = dataArray[counter][4];
col6.textContent = dataArray[counter][5];
row.appendChild(col1);
row.appendChild(col2);
row.appendChild(col3);
row.appendChild(col4);
row.appendChild(col5);
row.appendChild(col6);
tbody.appendChild(row);
counter +=1;
}
}
function filterFunction() {
// Declare variables
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[3]
if (td ) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
setValue function
function setValue(value) {
var ss = SpreadsheetApp.openByUrl(url);
var targetSheet = ss.getSheetByName('Target Lists');
targetSheet.getRange(1,ws.getLastColumn()+1,1,2).setValue(value);
}
table html
<table class="table table-hover" id="myTable"
data-custom-sort="customSort"
data-pagination="true"
data-ajax-options="ajaxOptions"
data-url="json/data1.json">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
District
</button>
<input type="text" placeholder="Search.." id="myInput" onkeyup="filterFunction()">
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Emery Unified</a>
<a class="dropdown-item" href="#">Mountain House Elementary</a>
</div>
</div>
<thead>
<tr>
<th scope="col">County</th>
<th scope="col">District</th>
<th scope="col">Position</th>
<th scope="col">Full Name</th>
<th scope="col">Date</th>
<th scope="col">Note</th>
</tr>
</thead>
<tbody id="table-body">
</tbody>
</table>
<input type="text" class="form-control" id="listName" placeholder="Type Name Here" aria-label="Username" aria-describedby="basic-addon1">
<button class="btn btn-dark" type="save" id="saveButton">Save</button>
</div> <!-- CLOSE AUTOFLOW -->
<button onclick='buttonFunction()'>Submit</button>
You can ignore my extra submit functions-I was testing out some other options.
pull the data I've filtered in my data and input it into the sheets.. Can I ask you about the detail of it?my filtered table. But I cannot understand about what you want to do frompopulates a column into a google sheet that I choose with those 3 school districts. So, I proposed the modified script by my guess for your goal. Could you please confirm it? If my guess was not correct, can I ask you about the detail of your goal?