but when i use edit page for Employee i used "EJS-for" to mapping wicth Deparmtnet he is,
i got this error and the DropdownTree is freezed
=======================
Uncaught TypeError: Cannot read properties of undefined (reading 'toString')
at t.setValidValue (ej2.min.js:1)
at t.setTreeValue (ej2.min.js:1)
at t.render (ej2.min.js:1)
at t.appendTo (ej2.min.js:1)
at 12:1903
=======================
if i removed "EJS-for" tag the DropdownTree is fill with all Departments
html code :
@model Attendance.Models.ViewModel.EmployeeVM
@using Syncfusion.EJ2
<ejs-dropdowntree id="tree" placeholder="أختر القسم" ejs-for="Employee.DepartmentId" enableRtl>
<e-dropdowntree-fields dataSource="ViewBag.dataSource" value="DepartmentId" parentValue="ParentId" text="DepartmentName" hasChildren="hasChild" expanded="expanded"></e-dropdowntree-fields>
</ejs-dropdowntree>
<span asp-validation-for="Employee.DepartmentId" class="text-danger"></span>
In short, when i disply employee details, including the name of the department in which he is, and when you click on the name of the department, get a all departments comes up in case you want to transfer the employee to another department
|
public ActionResult Index(SampleModel model)
{
ViewBag.data = new SampleModel().TreeViewdata();
model.DepartmentId = model.DepartmentId;
return View(model);
}
}
public class SampleModel
{
public String DepartmentId { get; set; }
public List<SampleModel> TreeViewdata()
{
List<SampleModel> treedata = new List<SampleModel>();
treedata.Add(new SampleModel
{
DepartmentId = "1",
DepartmentName = "Discover Music",
hasChild = true,
expanded = true
});
treedata.Add(new SampleModel
{
DepartmentId = "2",
ParentId = "1",
DepartmentName = "Hot Singles",
});
. . .
return treedata;
}
}
} |
Hi Shalini Maragathavel
Thank you for your example
What is you mentioned the reason for the error is because the field type was a integer and this is Logical because it is the serial number of the Departments
its means the "ejs-for" tag does not work with integer value
according to your example I defined a new variable"String" in Model and used it with "ejs-for" tag , and its worked The employee Department is selected in the DropDownTree,
but there was another aproblem if you notice the example you sent. you set a value for Department Id "21" by name "Redeem a Gift Card", but when run the example the Department select is Department Id "2" by name "Hot Singles"
it will take the first number of Department id , and if there no Department number that starts with the first digit, no Department will be selected
I hope there is a solution for that , thank you
Regards
Fahad
I temporarily solved the problem by doing the following
On GET - EDIT
Controller :
ViewBag.DepartmentId = employeeVM.Employee.DepartmentId;
View :
<ejs-dropdowntree id="DepartmentTree" Created="created" ejs-for="@Model.NewDepartmentId" enableRtl>
<e-dropdowntree-fields dataSource="ViewBag.dataSource" value="DepartmentId" parentValue="ParentId" text="DepartmentName" hasChildren="hasChild"></e-dropdowntree-fields>
</ejs-dropdowntree>
<span asp-validation-for="@Model.NewDepartmentId" class="text-danger"></span>
<script type="text/javascript">
function created(args) {
var treeObj = document.getElementById("DepartmentTree").ej2_instances[0];
var DepartmentId= @ViewBag.DepartmentId;
treeObj.value = [Parent.toString()];
}
</script>
On POST - EDIT
Controller :
obj.Employee.DepartmentId = int.Parse(obj.NewDepartmentId);
|
<ejs-dropdowntree id="tree" placeholder="أختر القسم" ejs-for="@Model.DepartmentId1" enableRtl>
. . .
</ejs-dropdowntree>
---------------------------------------------------------------------- public IActionResult Index() {
ViewBag.data = new SampleModel().TreeViewdata();
model.DepartmentId1 = new String[] {"21"};
return View(model);
}
public class SampleModel
{
public String[] DepartmentId1 { get; set; }
} |
Hi Shalini Maragathavel
Thank you for your example
The problem I was facing is solved