How can i refresh my table tag without reloading my page? In my current code, it refreshing but i notice that its like refreshing the whole document. I am trying to make a filter function where it filter the date only. So when i check 1 radio button and then fetch it, the radio button i checked will refresh also(became unchecked). So how i can refresh my table only? Help me with this please. I am doing this project since January 2018.
Code.gs
function doGet() {
return HtmlService
.createTemplateFromFile('Index')
.evaluate();
}
function getData() {
return JSON.stringify(SpreadsheetApp.openById('17lKIhONfEeNogsBhKtGr4zVaLgH0_199-3J3-0tAdcE')
.getActiveSheet()
.getDataRange()
.getValues());
}
function include(JavaScript) {
return HtmlService.createHtmlOutputFromFile(JavaScript)
.getContent();
}
function setApproved(a, b) {
var html = HtmlService.createTemplateFromFile('Index').evaluate().getContent();
var ss = SpreadsheetApp.openById('17lKIhONfEeNogsBhKtGr4zVaLgH0_199-3J3-0tAdcE');
var sheet = ss.getActiveSheet();
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
var headers = values[0];
var ldapIndex = headers.indexOf('dbName');
var idIndex = headers.indexOf('dbID');
var statusIndex = headers.indexOf('dbStatus');
var sheetRow;
for( var i = 1 ; i < values.length; i++ ) {
var row = values[i];
if(row[idIndex] == a && row[ldapIndex] == b) {
sheetRow = i +1;
break;
}
}
++statusIndex;
sheet.getRange(sheetRow, statusIndex).setValue('Approved');
return html;
}
function fetchData() {
var html = HtmlService.createTemplateFromFile('Index').evaluate().getContent();
return html;
}
Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<? var data = getData(); ?>
<div id="Options">
<label><b>Month</b></label>
<select id="selectMonth">
<option value="0">-Select Month-</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select> -
<input type="radio" name="radioYear" id="radioYear" value="<?= new Date().getYear(); ?>"> <?= new Date().getYear(); ?>
<input type="radio" name="radioYear" id="radioYear2" value="<?= new Date().getYear()+1; ?>"> <?= new Date().getYear()+1; ?>
<button id="btnFetch" onclick="google.script.run.withSuccessHandler(fetchRecord).getData()">Fetch</button>
</div>
<div id="tables">
<table id="tableShift2">
<caption>Team unknown</caption>
<th> Date and Time Plotted </th>
<th> Name </th>
<th> Date of VL </th>
<th> HD/WD </th>
<th> Action </th>
</table>
</div>
<div id="date"></div>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
google.script.run.withSuccessHandler(showData)
.getData();
});
function showData(things1) {
var things = JSON.parse(things1);
var table = $('#tableShift2');
for (var i = 1; i < things.length; i++) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var date = new Date(things[i][1]);
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
if (things[i][6] == '') {
table.append('<tr> <td>' + monthNames[monthIndex] + ' ' + day + ', ' + year + ' ' + hour + ':' + minute + ':' + second +
'</td> <td>' + things[i][2] +
'</td> <td>' + things[i][3] +
'</td> <td>' + things[i][4] +
'</td> <td ><button onclick=\'ApproveAndRefresh("' + things[i][0] + '","' + things[i][2] +
'")\' id="btnApprove">Approve</button> <button onclick=\'DeclineAndRefresh("' + things[i][0] + '","' + things[i][2] +
'")\' id="btnDecline">Decline</button></td></tr>');
}
}
}
function ApproveAndRefresh(data, data1){
google.script.run
.withSuccessHandler(refreshData)
.setApproved(data, data1);
}
function DeclineAndRefresh(data, data1){
google.script.run
.withSuccessHandler(refreshData)
.setDeclined(data, data1);
}
function refreshData(hl){
document.open();
document.write(hl);
document.close();
}
</script>
</body>
</html>