Search code examples
django-viewshandsontable

django - Passing data to view without a form


I'm using Hansontable to allow users to create a matrix of input variables. How do I pass this matrix back to my views.py without it being part of the input form? I can add a form field for a 2-dimensional array, but I don't actually need it since the hansontable is creating the "input field".

I need to compute a set of results using the matrix before echoing it back to the user along with the results and storing it in a bd.

Any guidance is greatly appreciated.

Thanks.


Solution

  • To do pass any data to a backend without using a HTML form (without refreshing the page) you have to utilize AJAX methodologies/practice. Using jQuery you can do this like so:

    $.ajax({
      method: "POST",
      url: "/some/url",
      data: JSON.stringify(<handsontabledom>.getData())
    })
      .done(function( msg ) {
        alert( "Data Saved: " + msg );
      });
    

    Also note there is a tutorial on the Handson Tables documentation all about saving the data via a ajax request.

    http://docs.handsontable.com/0.19.0/tutorial-load-and-save.html