We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Refresh gantt datasource on server side

Hi,

The webpage has a chart gantt and datepicker. When you change the date gantt chart should be refreshed with new content generated data source on the server side. 
How best to perform this operation avoiding unnecessary refresh the entire page?

Regards,
RobertS

3 Replies

JR John Rajaram Syncfusion Team April 24, 2015 03:58 PM UTC

Hi Robert,

Thanks for using Syncfusion product.

We have analyzed your query and prepared a sample based on your requirement for updating the new datasource in Gantt control while changing the date in the ejDatePicker control without refreshing the browser.

Please refer the following code snippets for more details.

Code snippets:


<body>

@Html.EJ().DatePicker("DatePick").ClientSideEvents(s => s.Close("onClose"))

<br />


@(Html.EJ().Gantt("Gantt")


//...


.Datasource(ViewBag.datasource)


)

@(Html.EJ().ScriptManager())


<script type="text/javascript">


var ganttData1=@Html.Raw(Json.Encode(ViewBag.dataSource)),

ganttData2=@Html.Raw(Json.Encode(ViewBag.dataSource1)),

flag=true;


function onClose(args) {

var ganttObject = $("#Gantt").data("ejGantt");

if(flag){

ganttObject.setModel({ dataSource: ganttData2 });

flag=false;

}

else{

ganttObject.setModel({ dataSource: ganttData1 });

flag=true;

}

}


</script>

</body>


Please find the sample in the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/118926/MVCsampleSQL90336456.zip

If this is not your exact requirement, we request you to share more details regarding your queries and revert to us by modifying our sample.

Please let us know if you have any questions about this.
Regards,
John R




RO RobertS April 24, 2015 06:46 PM UTC

Hi, 

Thank you for your example. I found some other solution that works in a similar way but allows for more 
efficient communication with the controller. Anyway thanks for the suggestion.

....

              @(Html.EJ().DatePicker("startDate")
                    .Value(Model.Data.StartDate)
                    .ClientSideEvents(cs=>cs.Change("OnStartDateChanged"))

              @(Html.EJ().Gantt("gantt")
              // ...
              .Datasource(ViewBag.datasource)

....


        function OnStartDateChanged(args) {
            $.ajax("/Controller/RefreshData" { type: "POST", data: { date: args.value } })
              .done(function(result) {
                var ganttObject = $("#gantt").data("ejGantt");
                if (ganttObject) {
                    ganttObject.setModel({ dataSource: result.List.Data });
                }
              });
        }

Regards,
RobertS


MK Mahalakshmi Karthikeyan Syncfusion Team April 27, 2015 10:37 AM UTC

Hi Robert,

Thanks for the update.

Yes, we can also refresh the Gantt data source in the Controller using AJAX post method.

Please let us know if you want further assistance on this.

Regards,

Mahalakshmi K.


Loader.
Live Chat Icon For mobile
Up arrow icon