Retrieving data from a handsontable
Hi All!
I am trying to learn how to use the handsontable from the demos and I am having the devil's time of it. I can get the table to display, I can put data into but I cannot, for the life of me, figure out how to retrieve the data.
For NOW, the intent is to retrieve the data, put it in a hidden <INPUT> so I can submit it via POST. This will change to ajax at some point.
Here's what I have so far.
First, here's the HTML:
- <div class="handsontable" id="example"></div>
- <input type="button" name="submit" value="submit" onclick="submitForm()" />
- <input type="hidden" id="hidGridContents" />
Now the handsontable setup (which works). It's in the document ready function
- var data = [
- ["", "Maserati", "Mazda", "Mercedes", "Mini", "Mitsubishi"]
- ];
-
- $('#example').handsontable({
- data: data,
- minSpareRows: 1,
- colHeaders: true,
- contextMenu: true
- });
Finally, the code that is supposed to retrieve the information:
- <script type="text/javascript">
- function submitForm(){
- var $container = $('#example');
- var ht = $container.handsontable('getInstance');
- var htContents = ht.getData();
-
- $('#hidGridContents').val(htContents);
- alert(htContents);
- }
- </script>
In this last code snippet, Line 3 gives me a valid reference, line 4 executes and then skips to the end of the code. I assume it is because an error occurred but I am not seeing anything in the console.
Any assistance would be greatly appreciated.
Thanks in advance.