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

Gantt as a partial view

Hello,

Looks like Gantt is too much sensitive. I am trying since last 2 days for very very little thing : Returning partial view.

Theres a page which loads Gantt as a partial view. It works as expected. Problem comes when i am trying to refresh the view. e.g. Theres one dropdown. On changing it,Ajax call will be made which returns partial view as follows:

AJAX Call

 $.ajax({
            type: "POST",
            url: urlGetGantt,
            dataType: 'html',
            data: "{'Type':'" + $(this).val() + "'}",
            contentType: "application/json; charset=utf-8",
            success: function (data) {                
                $("#Gantt").html(data);
            }
        });

Web Method

 [HttpPost]
 public ActionResult gantt(int Iteration)
 {
     return PartialView("Gantt", GetGantt(Iteration));
 }

I'm able to observe the data coming properly from web method. But nothing is getting displayed. Is there something which i'm missing. No errors are there even in console.

Note : All the scripts are loaded already from layout. Only CSS are there on partial file.


8 Replies

MK Mahalakshmi Karthikeyan Syncfusion Team October 28, 2016 12:36 PM UTC

Hi Manish, 
Thanks for contacting Syncfusion support. 
We have analyzed your query and came to know that you want to change the Gantt dataSource which is in partial with the data source selected in the drop down list. It is possible to update the Gantt data source via setModel with the data returned from the controller. Please refer the below code example for details. 
<script> 
        /*Change event for Dropdown control*/ 
        function dataChanged(args) { 
            debugger; 
            /*Get Data for Treeview and TreeGrid*/ 
            var name = args.text, value; 
            $.ajax 
            ({ 
                url: "Gantt/GetGanttData", 
                async: false, 
                data: { text: name }, 
                type: 'GET', 
                dataType: "json", 
                contentType: "application/json;charset=utf-8", 
                success: function (result) { 
                    value = result.dataSource; 
                    $("#GanttContainer").ejGantt("model.dataSource", value); 
                }, 
                error: function (data) { 
                    alert("error"); 
                } 
            });             
        } 
    </script> 
 
[CS] 
 
  public JsonResult GetGanttData(string text) 
        { 
            List<BusinessObject> ds = new List<BusinessObject>();  
            if(text=="DataSource1") 
                ds = this.GetPlanDataSource(); 
            else 
                ds = this.GetDesignDataSource(); 
            return Json(new { dataSource = ds }, JsonRequestBehavior.AllowGet); 
        } 
        
We have also prepared the sample for your reference. Please find the sample from below location  
Sample: 
Regards, 
Mahalakshmi K. 



MK Mahalakshmi Karthikeyan Syncfusion Team October 28, 2016 12:42 PM UTC

Hi Manish, 
please ignore the previous update 
We have analyzed your query and came to know that you want to change the Gantt dataSource which is in partial with the data source selected in the drop down list. It is possible to update the Gantt data source via setModel with the data returned from the controller. Please refer the below code example for details. 
<script> 
        /*Change event for Dropdown control*/ 
        function dataChanged(args) { 
            debugger; 
            /*Get Data for Treeview and TreeGrid*/ 
            var name = args.text, value; 
            $.ajax 
            ({ 
                url: "Gantt/GetGanttData", 
                async: false, 
                data: { text: name }, 
                type: 'GET', 
                dataType: "json", 
                contentType: "application/json;charset=utf-8", 
                success: function (result) { 
                    value = result.dataSource; 
                    $("#GanttContainer").ejGantt("model.dataSource", value); 
                }, 
                error: function (data) { 
                    alert("error"); 
                } 
            });             
        } 
    </script> 
 
[CS] 
 
  public JsonResult GetGanttData(string text) 
        { 
            List<BusinessObject> ds = new List<BusinessObject>();  
            if(text=="DataSource1") 
                ds = this.GetPlanDataSource(); 
            else 
                ds = this.GetDesignDataSource(); 
            return Json(new { dataSource = ds }, JsonRequestBehavior.AllowGet); 
        } 
        
We have also prepared the sample for your reference. Please find the sample from below location  
Regards, 
Mahalakshmi K. 



MD Manish dhariwal October 29, 2016 08:08 AM UTC

hanks for the reply.

I may be able to set datasource this way,but this will create problem with large datasets. There are chances for maxjsonlength error. Thats the reason i am looking to refresh whole view. I am still not clear,why its not possible or working?

It would be great if you can show me the example where partial view along with the data is returned from controller.


JS Jonesherine Stephen Syncfusion Team October 31, 2016 07:50 PM UTC

Hi Manish, 
By using serialization method we can render the Gantt with large datasets. 
We have prepared the work around and rendered the Gantt in partial view and also rendered the large data sets by using serialization method. 
Please find the code example below: 
  public ActionResult Index() 
        { 
               // 
            ViewBag.datasource = this.GetPlanDataSource(); 
            DataManagerConverter.Serializer = new DMSerial(); 
            return View(); 
        }        
public class DMSerial : IDataSourceSerializer 
        { 
 
            public string Serialize(object obj) 
            {    
                var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj); 
                return str; 
            } 
        } 
Please find the sample from below location 
Is this your requirement? If not could you please share us more details regarding your requirement with us. It would be helpful for us to serve you better. 
Please let us know if you need more information on this.
Regards,
 
Jone sherine P S 



MD Manish dhariwal November 2, 2016 08:07 AM UTC

Would you please show me ,how can i refresh partial view as we do it normally and shown in the code snippet i've posted? I tried to implement the code shown by Mahalakshmi Karthikeyan,but nothing happens.

In the example you've posted, i see no partial view refresh,AJAX calls,etc.


JS Jonesherine Stephen Syncfusion Team November 3, 2016 03:59 PM UTC

Hi Manish, 
We regret about the inconvenience caused 
We have prepared the work around and rendered the Gantt in partial view. During load time we have referred the Gantt in a main view and we have refreshed the Gantt’s partial view on drop down control’s change event. Please find the code example below: 
//Triggered on drop down change action 
        function change(args) {            
            var data = { id: args.value }; 
            //ajax call to server side method to refresh partialView 
            $.ajax({ 
                data: data,  
                url: '@Url.Action("_Gantt", "Gantt")',                 
                success: function (data) { 
                                        $("#GanttContainer").ejGantt("destroy"); 
                    $("#container").html(data); 
                }, 
                error: function (result) { 
                    alert("Error"); 
                } 
            }); 
        } 
Server side method 
[HttpGet] 
        public ActionResult _Gantt(int id) 
        { 
            var DataSource = this.GetDesignDataSource(id); 
            ViewBag.datasource = DataSource;            
            DataManagerConverter.Serializer = new DMSerial(); 
            return PartialView("_Gantt", DataSource);            
        } 
We have also prepared the sample and dynamically updated the record count as per drop down count selection for your reference. 
 
Please let us know if you need further assistance on this. 
Regards, 
Jone sherine P S 



MD Manish dhariwal November 7, 2016 09:29 AM UTC

I tried everything as you said. Nothing is working. The whole setup is as follows:

- Scripts are loaded through Layout page 

    <script src="~/JsScript/PageScripts/HRIMS_Secure/jquery-2.1.4.min.js"></script>

    <script src="http://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>

    <script src="~/JsScript/Gantt/jquery.easing-1.3.min.js"></script>

    <script src="~/JsScript/Gantt/jsrender.min.js"></script>

    <script src="~/JsScript/Gantt/ej.web.all.js"></script>

    <script src="~/JsScript/Gantt/ej/ej.unobtrusive.min.js"></script> 

-Layout page also contains   @(Html.EJ().ScriptManager())

- <add key="UnobtrusiveJavaScriptEnabled" value="false" />(I still needs to load ej.unobtrusive.min.js the chart is not at all working)

- Index.cshtml contains PartialView(_Gantt) which is attached here.Please find attachment.

-  $('#drp').change(function () {

       

        $.ajax({

           

            url: urlGetGantt,

                   

            data: {Id:  $(this).val() },

           

            success: function (data) {

                

                $("#GanttContainer").ejGantt("destroy");

                

                $("#Gantt").html(data);

             

            }

        });

       

    });

Above is the change event of the dropdown.  After refresh no errors are there. Only below html is loaded if i view it in console

<div id="Gantt">

<link rel='nofollow' href="/CSS/ej.widgets.core.min.css" rel="stylesheet">

<link rel='nofollow' href="/CSS/ej.theme.min.css" rel="stylesheet">

<link rel='nofollow' href="http://cdn.syncfusion.com/13.1.0.21/js/web/flat-azure/ej.web.all.min.css" rel="stylesheet">


    <div id="GanttContainer" data-role="ejgantt" data-ej-enablecontextmenu="true" data-ej-allowcolumnresize="true".......</div><script>ej.createObject("ej.dataSources.GanttContainer",{"data0":ej.isJSON([{........</script>

This is the method in controller

 [HttpGet]

    public ActionResult gantt(int Id)

    {    GanttData objGanttData = new GanttData();

        if (Id != 0)

        {

            objGanttData.LstTaskData = GetData(iteration);

            objGanttData.LstTaskData = GetData(iteration);

            objGanttData.StripLines = GetStriplines();

        }
        objGanttData.LstAllResource = GetResources();

        objGanttData.objPriorityCodes = JsonConvert.SerializeObject(GetPriorities(), Formatting.None);

        objGanttData.objProjectWiseStatus = JsonConvert.SerializeObject(GetStatus(), Formatting.None);

        objGanttData.objWorkItemTypes = JsonConvert.SerializeObject(GetWorkItemType(), Formatting.None);

        DataManagerConverter.Serializer = new DMSerial();       

        return PartialView("gantt", objGanttData);     

    }

Note: Chart stops working only after partial view refresh. If we pass data at the time of page load,it gets rendered as expected.

I'm really getting confused as what is missing here.


Attachment: gantt_3e97840.rar


JS Jonesherine Stephen Syncfusion Team November 8, 2016 05:23 PM UTC

Hi Manish, 
We deeply regret about the inconvenience caused 
We have analyzed the report query with our sample.  
As per the provided page source the sample is rendered in unobtrusive mode. 
<div id="GanttContainer" data-role="ejgantt" data-ej-enablecontextmenu="true" data-ej-allowcolumnresize="true".......</div><script>ej.createObject("ej.dataSources.GanttContainer",{"data0":ej.isJSON([{........</script> 
Please ensure whether the “UnobtrusiveJavaScriptEnabled” is set to false in web config file.  If UnobtrusiveJavaScriptEnabled is set to false then there is no need to refer the unobtrusive.min.js file. 
And refer the theme files along with script files in _layout page to avoid the css conflicts. 
Regards, 
Jone sherine P S 


Loader.
Up arrow icon