Search code examples
tabulator

table.getdata returns an empty string


I want to save the table to a text file after making changes. When I click the save button tbldata is empty and my text file is overwritten and blank.

I have tested the button with: var tbldata = JSON.stringify([{"id":1, "name":"Bob"}]) and it works.

I am assuming I am using table.getData incorrectly. Where and how in my button function should var tbldata = table.getdata be located?

I cannot find a specific example in the documentation

	<button class="button" id="save-data" >Save 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> 


Solution

  • There are two issues there, it is getData not getdata and you a not actually calling the function because you are missing the parenthesis after the function name. It should be:

    var tbldata = table.getData();