I am using https://handsontable.com . But how can I get data with MVC ? Can anyıne help me please.
HTML
<div id="hot"></div>
MVC CS
public JsonResult Tables()
{
using (PortfoliosContext port = new PortfoliosContext())
{
var dil = port.TProjeCategory.AsQueryable().ToList();
ViewBag.Cat = dil;
return Json(dil);
}
}
JS
<script>
(function ($) {
if ($) {
var hst = (function () {
var $container = $("#hot");
$container.handsontable({
startRows: 8,
startCols: 6,
rowHeaders: true,
colHeaders: true,
minSpareRows: 1,
contextMenu: true
});
hst = $container.data('handsontable');
var $dataLocker = $("#Tables").val();
if ($dataLocker.length > 0) {
var data = JSON.parse($dataLocker);
hst.loadData(data);
}
return hst;
})();
}
})(jQuery);
</script>
The basic idea is to use Jquery Ajax to call server side function and return json data :
jQuery.ajax({
url: '/Home/GetCar', //Controller to Get the
//JsonResult From -- Json(jsonData, JsonRequestBehavior.AllowGet);
type: "GET",
dataType: "json",
contentType: 'application/json;
charset=utf-8', // dataType and contentType should be json
async: true,
processData: false,
cache: false,
success: function (data) { // on Success send the Json data
// to the table by using loaddata function""
//alert(data);
hot.loadData(data);
exampleConsole.innerHTML = 'Data loaded';
},
error: function (xhr) {
alert('error');
}
});
Please take a look at this example for more details on how to implement "Handsontable" with MVC
Member
22 Points
312 Posts
Handsontable Get Data MVC
Apr 03, 2019 05:05 PM|Aliyilmaz|LINK
Hi,
I am using https://handsontable.com . But how can I get data with MVC ? Can anyıne help me please.
HTML
MVC CS
JS
https://www.portakalahsap.com
https://www.portakalahsap.com/ofis-mobilyalari
All-Star
18815 Points
3831 Posts
Re: Handsontable Get Data MVC
Apr 04, 2019 01:50 AM|Nan Yu|LINK
Hi Aliyilmaz,
The basic idea is to use Jquery Ajax to call server side function and return json data :
Please take a look at this example for more details on how to implement "Handsontable" with MVC
http://www.codeproject.com/Tips/1074230/Load-and-save-Handsontable-data-from-to-Controller
Best Regards,
Nan Yu
Member
92 Points
534 Posts
Re: Handsontable Get Data MVC
Apr 06, 2019 11:08 AM|fatihbarut|LINK
Don't know handsontable but if you need to get data from an MVC controller just follow this technique.
Lets say you use Entity frame work and you simply need Turkiye'nin Illeri list. Make a controller like this.
now use jquery $.get method to get that list as data
If you need data as json (probably you will need it for handsome one :) you need to convert It to json like below
and this time you need to use getJson instead of simple get
Member
22 Points
312 Posts
Re: Handsontable Get Data MVC
Apr 07, 2019 10:55 AM|Aliyilmaz|LINK
I try this but it doesnt work,
I get error below code. "Uncaught TypeError: Cannot read property 'addEventListener' of undefined"
Handsontable.Dom.addEvent(load, 'click', function () {
https://www.portakalahsap.com
https://www.portakalahsap.com/ofis-mobilyalari
All-Star
18815 Points
3831 Posts
Re: Handsontable Get Data MVC
Apr 08, 2019 01:57 AM|Nan Yu|LINK
Hi Aliyilmaz ,
Try to change Dom to dom ,seems Handsontable make the changes from version v1.11.0 :
https://forum.handsontable.com/t/cannot-read-property-addevent-of-undefined/1372
Best Regards,
Nan Yu