function onCustomerChange(args) { var ddlCustomer = $("#IdCustomer").data("ejDropDownList"); var curCutomerId = ddlCustomer.getSelectedValue(); var objData = { idCustomer: curCutomerId }; var str = JSON.stringify(objData); $.ajax({ type: "POST", contentType: "application/json", url: "@Url.Action("GetCustomerProjects", "Customer")", data: str }) .done(function (data) { alert(data.success); var grid = $("#TreeGridContainer").data("ejTreeGrid"); grid.dataSource = data.data; //onClose(); }) .fail(function (data) { alert("error"); }) .always(function () { //alert("finished"); }); }
Hi Andrea,
Thanks for using Syncfusion products.
We have referred your code snippets. We request you to assign the values for data source as like as following code snippets, instead of “grid.dataSource = data.data;” to reload the data on the TreeGrid.
Code snippets:
//...
treeObject = $("#Tree").data("ejTreeGrid");
//...
treeObject.setModel({ dataSource: projectData }); |
Please refer the following code snippets for more details.
Code snippets:
<body style="position: static; margin: 0px; padding: 2px">
<div class="ctrllabel"> Datasource </div> <br /> @(Html.EJ().DropDownList("Datasource").TargetID("dataList").Value("DataSource 1").Width("150px").ClientSideEvents(e => e.Change("onChange"))) <div id="dataList"> <ul> <li>DataSource 1</li> <li>DataSource 2</li>
</ul> </div> <br />
@(Html.EJ().TreeGrid("Tree") //... .Datasource((System.Collections.IEnumerable)ViewBag.datasource) ) @(Html.EJ().ScriptManager()) <script>
//...
function onChange(args) {
treeObject = $("#Tree").data("ejTreeGrid"); if (args.text === "DataSource 1") { treeObject.setModel({ dataSource: projectData }); } if (args.text === "DataSource 2") { treeObject.setModel({ dataSource: datas }); } }
</script>
</body> |
We have prepared a sample for reloading the data source. Please find the sample in the following location.
Please let us know if you need more information on this.
Regards,
John. R
Hi Pankaj,
Thanks for using Syncfusion product,
For your kind information, we were unable to reproduce the issue you have reported. We can able to serialize the data in server side and also we can populate those data to the TreeGrid. Please refer the below code snippet to achieve this.
[CS] namespace TreeGridSample.Controllers { public class TreeGridController: Controller { //… [HttpPost()] public string CustomerData() { var DataSource = TreeGridDefaultData.GetMethodData(); var datasource = JsonConvert.SerializeObject(DataSource); return datasource; } public class TreeGridDefaultData { public static List < DefaultData > GetMethodData() { //… } } } } |
[CSHTML] <button id="loadDataSource"> New Data Source</button> @(Html.EJ().TreeGrid("TreeGridContainer"). //… ) <script type="text/javascript"> $("#loadDataSource").click(function () { $.ajax({ type: "POST", url: "/TreeGrid/CustomerData", dataType: "json" }).done(function (data) { var grid = $("#TreeGridContainer").data("ejTreeGrid"); grid.setModel({dataSource: data}); }) }); </script> </body> |
Here we have changed the TreeGrid data source in the button click event which was serialized and returned from the server using AJAX post method.
We have also prepared a sample based on this and you find the sample under the following location.
Sample: http://www.syncfusion.com/downloads/support/forum/118206/ze/Serialize906535915
Is this your requirement or else please get back us by modifying this sample along with the replication procedure.
And please let us know if you need further assistance on this.
Regards,
Mahalakshmi K.
[HttpPost]
public JsonResult CustomerData()
{
var DataSource = TreeGridDefaultData.GetMethodData();
//var datasource = JsonConvert.SerializeObject(DataSource);
return Json(DataSource, JsonRequestBehavior.DenyGet);
}
Hi Pankaj,
Thanks for the update.
We glad to know that your issue has been resolved.
Please let us know if you need further assistance on this.
Regards,
Mahalakshmi K.