Reputation: 193
I´m done in updating the cell and now I want to refresh automatically the tag after i click the button looped by on the table using google-app-script
. Cannot understand the coding in the documentation. Please help me to solve this. Thanks!
html
<div id="tables">
<? var data = getData();?>
<table id="tableShift1">
<caption style="">Shift1</caption>
<th> ID </th>
<th> Ldap </th>
<th> Action </th>
<? for (var dataList = 1; dataList < data.length; dataList++) {
if (data[dataList][2] == '') {?>
<tr >
<td><?= data[dataList][0] ?></td>
<td><?= data[dataList][1] ?></td>
<td><button onclick='google.script.run.setApproved("<?=data[dataList][0]?> ","<?=data[dataList][1]?>")' id='btnApprove'>Approve</button></td>
</tr>
<? }
} ?>
</table>
<table id="tableShift2">
<caption>Shift2</caption>
<th> ID </th>
<th> Ldap </th>
<th> Action </th>
</table>
</div>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
// The code in this function runs when the page is loaded.
$(function() {
google.script.run.withSuccessHandler(showData)
.getData();
});
function showData(things2) {
var table = $('#tableShift2');
var kwit = ',';
for (var i = 1; i < things2.length; i++) {
table.append('<tr ><td>' + things2[i][0] +
'</td><td style=>' + things2[i][1]+ things2[i][0] +
'</td><td ><button onclick="google.script.run.setApproved("'+ things2[i][0] +'","'+ things2[i][1] +'")" id="btnApprove">Approve</button></td></tr>');
}
}
</script>
</body>
Upvotes: 0
Views: 744
Reputation: 64042
You might try something like this:
Add and new function that provides the ability to return new data to refreshData()
function showData(things2) {
var table = $('#tableShift2');
var kwit = ',';
for (var i = 1; i < things2.length; i++) {
table.append('<tr ><td>' + things2[i][0] +
'</td><td style=>' + things2[i][1]+ things2[i][0] +
'</td><td ><button onclick="ApproveAndRefresh("'+ things2[i][0] +'","'+ things2[i][1] +'");" id="btnApprove">Approve</button></td></tr>');
}
}
function ApproveAndRefresh(data1,data2){//you may need to include i
google.script.run
.withSuccessHandler(refreshData)
.setApproved1(data1,data2);//a modified setApproved on the server that returns the appropriate html to the tableShift2 element
}
function refreshData(hl){
document.getElementById('tableShift2').innerHTML=hl;
}
Upvotes: 1