I am new to javascript and trying to create a interface to manipulate arrays stored in text files stored on a server. I am using Tabulator 4.1 which is a javascript library (no jQuery) that display data.
Link
The table loads properly and I can edit the data, but when I click the save button my text file is overwritten with an empty string. Per the documentation on Tabulator
saves the entire table contents into a JSON encoded string.
I am guessing that I am not using var tbldata = table.getdata properly. I tried to stringify the variable, but that did not work. I know the button works if I set an array to a variable and save it.
Here is the entire script.
Thank you for any help.
Link
The table loads properly and I can edit the data, but when I click the save button my text file is overwritten with an empty string. Per the documentation on Tabulator
JavaScript:
var tbldata = table.getdata
I am guessing that I am not using var tbldata = table.getdata properly. I tried to stringify the variable, but that did not work. I know the button works if I set an array to a variable and save it.
Here is the entire script.
JavaScript:
<body>
<div id="tblwrap">
<h2>Meeting Information Editor</h2>
<div id="meetinfo-table"></div>
<button class="button" id="save-data" >Save Data</button>
<button class="button" id="download-json" >Download Data</button>
<script>
//create Tabulator on DOM element
var table = new Tabulator("#meetinfo-table", {
height:200, // set height of table (in CSS or here)
selectable:true, //make rows selectable
layout:"fitDataFill",//fit columns to fit data and width of table (optional)
//Sort data decending
initialSort:[
{column: "meetdate", dir:"desc"}],
//Define Table Columns
columns:[
{title:"Meeting Date", field:"meetdate", width:150, editor:"input"},
{title:"Topic", field:"topic", align:"left", editor:"input"},
{title:"Speaker", field:"speaker", editor:"input"},
{title:"Room", field:"room", editor:"input"},
{title:"CE", field:"ce", align:"left", editor:"input"},
{title:"RSVP Survey Code", field:"rsvpcode",editor: "input"},
{title:"RSVP Due Date", field:"rsvpduedate", editor:"input"},
],
});
//Saves entire table to JSON encoded string
var button = document.getElementById("save-data");
button.addEventListener("click", function(){
//********************************************************************************
var tbldata = table.getdata;
//********************************************************************************
var request= new XMLHttpRequest(); // new HttpRequest instance
request.open("POST", "process.php");
request.setRequestHeader("Content-type", "application/json");
request.send(tbldata);
});
//loads data into the table
table.setData('meetinfo_array.txt');
</script>
</div>
</body>
Thank you for any help.