down load data using ViewBag and Javascript to Gantt control in asp net core 3.1 ej2

Hi Guys
I am trying to download data from controller using a button on view, I want to download data using ViewBag to a Gantt control.
I am using asp net core 3.1 and EJ2 with latest nuget packages with little success, please point me in the right direction
The ViewBag I am using works if i use it when view opens with normal data manager dataSource="ViewBag.dataSource"

but does not work when using javascript below

I want to only load Gantt chart data when down load button is triggered and not when view opens.

Example Javascript used

document.getElementById('getData').onclick = function() {
reloadData();

};

function test() {
setTimeout(function() {
gridData = '@Html.Raw(Json.Serialize(ViewBag.dataSource))';
alert(gridData);var gridObj = document.getElementById('Gantt')['ej2_instances'][0];
gridObj.dataSource = gridData;
gridObj.refresh();

}, 3000);
}


function reloadData() {

var obj = document.getElementById("Gantt").ej2_instances[0];
var newData = new ej.data.DataManager({
url: '/GanttChart/GetMyData',
adaptor: new ej.data.UrlAdaptor,
crossDomain: true
});
test();
Your help would be appreciated
Regards
Edmund Herbert

1 Reply 1 reply marked as answer

PP Pooja Priya Krishna Moorthy Syncfusion Team November 12, 2020 01:24 PM UTC

Hi Edmund, 
Thanks for contacting Syncfusion support. 
We have prepared a sample based on your requirement. We fetched data from ViewBag, on button click action as like below code example. 
 
<button onclick="getData()">Fetch Data</button> 
function getData() { 
   var obj = document.getElementById('Gantt').ej2_instances[0]; 
   obj.dataSource = JSON.parse('@Html.Raw(Json.Serialize(@ViewBag.DataSource))'); 
} 
 
 
Regards, 
Pooja K. 


Marked as answer
Loader.
Up arrow icon