Hi Team,
Can you help me on how to create Dropdown Tree in blazor wasm. I saw that the feature is still in your pipeline and is not yet implemented in the current release. is it possible to implement using Ej2 javascript control, if so can you give me a sample project on how to do that?
|
[index.razor]
<div>
<button class="btn btn-primary" @onclick="@CallJSMethod">Render JS Dropdown Tree</button>
</div>
<div id="ddltreeelement"></div>
@code
{
public async void CallJSMethod()
{
await jsRuntime.InvokeAsync<object>("JSMethod");
}
}
[index.html]
<link rel='nofollow' href=https://cdn.syncfusion.com/ej2/material.css rel="stylesheet" type="text/css" />
<!-- Essential JS 2 Dropdown Tree's dependent scripts -->
<script src=https://cdn.syncfusion.com/ej2/dist/ej2.min.js type="text/javascript"></script>
<script>
function JSMethod() {
//define the nested array of JSON objects
var continents = [
{
code: 'AF', name: 'Africa', countries: [
{ code: 'NGA', name: 'Nigeria' },
{ code: 'EGY', name: 'Egypt' },
{ code: 'ZAF', name: 'South Africa' }
]
},
...
...
];
if (document.getElementsByClassName('e-dropdowntree')[0] == undefined) {
var DropDownTreeObj = new ej.dropdowns.DropDownTree({
fields: { dataSource: continents, value: 'code', text: 'name', child: 'countries' }
});
DropDownTreeObj.appendTo('#ddltreeelement');
}
}
</script> |
Thanks a lot, This was a life saver.
Appreciate the quick response
How do I bind value in blazor though.
Can you show me how to do it with type script files, since all the documentation on ej2 is on type script.
|
var DropDownTreeObj = new ej.dropdowns.DropDownTree({
fields: { dataSource: continents, value: 'code', text: 'name', child: 'countries' },
value: ['CUB']
});
DropDownTreeObj.appendTo('#ddltreeelement'); |
Hi Indumathy,
Thanks for the reply but my question was on how to bind data changed from this dropdown to Blazor side, so that an event will be triggered and other components state will be changed
Hi Shameer,
We have a multi-layered hierarchical list of locations. For example :-
|
[index.html]
<script>
function JSMethod(dotNetHelper) {
......
if (document.getElementsByClassName('e-dropdowntree')[0] == undefined) {
var DropDownTreeObj = new ej.dropdowns.DropDownTree({
fields: { dataSource: continents, value: 'code', text: 'name', child: 'countries' },
value: ['CUB'],
select: select
});
DropDownTreeObj.appendTo('#ddltreeelement');
function select(args) {
if (args.action == "select") {
return dotNetHelper.invokeMethodAsync('GetSelectedText', args.itemData.text);
}
}
}
}
</script>
[index.razor]
private DotNetObjectReference<Index>? objRef;
public async void CallJSMethod()
{
objRef = DotNetObjectReference.Create(this);
await jsRuntime.InvokeAsync<object>("JSMethod", objRef);
}
[JSInvokable]
public string GetSelectedText(string passedName) => $"Selected Item, {passedName}"; |
This worked out great, thanks guys for the support
Hi Team,
Facing some issues while implementing the dropdown. The options in the dropdown are overflowing outside the control. Once the dropdown is clicked the options disappear and work as expected. the first time it loads it is overflowing out of bounds
We are not able to user ej2 material css since it will impact our current design. Can you help us solve this issue using the required css.
You can find the solution here https://zcodelabs-my.sharepoint.com/:u:/p/alen_mathew/ESxLzHmxUedChfGeTCm4o5YB_ZcG3f4P7wbM2H8R34_m5Q?e=3Jzbdo
|
<style>
.e-treeview {
display: none;
}
.content p {
display: none;
}
</style> |
Hi Team,
When the css was implemented the current coloring scheme and looks changed. which is why opted to not use it.
Didn't know about the theme studio. Will give it a try.
Thanks for the quick response
Hi Team,
We have an issue in the current implementation. we get our data through api and there's a bit of delay in getting data.
By the time API call is finished the tree is already rendered, so we cannot set the selected value of ddtree from the razor component.
We have tried to replicate the issue the best we can with the attached solution
Also , when can we expect a DDtree component for blazor from syncfusion
|
<script>
var selectedVal;
function RenderLocationTree(dotNetHelper, ds, id, selectedVal) {
selectedVal = ds;
var DropDownTreeObj = new ej.dropdowns.DropDownTree({
fields: { dataSource: ds, text: 'name', value: 'id', parentValue: 'pid', hasChildren: 'hasChild' },
placeholder: 'Select a default location',
select: select,
created: () => {
DropDownTreeObj.value = ds[0].id;
}
});
DropDownTreeObj.appendTo('#' + id);
function select(args) {
if (args.action == "select") {
return dotNetHelper.invokeMethodAsync('GetSelectedText', args.itemData.id);
}
}
}
</script> |
Hi Team,
Can we trigger an event when clicking on the clear button in drop down tree?. We want to change the data in local storage when clearing the dropdown tree
|
function onChange(args) {
if (args.value.length == 0) {
console.log("selected items cleared");
}
} |
Hi
I'm trying to pass a Query from the custom component to the DropdownTree component but it doesn't seem to be working.
Can you kindly help with this?
Hi
I'm using the sample Blazor application you created in this thread and I have a query defined in C# and would like to pass down the query to the ejs DropdownTree.
[index.html]
<script>function RenderDropDownTree(dotNetHelper, ds, id, selectedVal, displayProp, parentIdProp, placeholderTxt, query) { var DropDownTreeObj = new ej.dropdowns.DropDownTree({ fields: { dataSource: ds, text: displayProp, value: 'id', parentValue: parentIdProp, hasChildren: 'isParent', query: query }, itemTemplate: '#itemTemplate', placeholder: placeholderTxt, value: String(selectedVal), select: select, change: onChange, popupWidth: '650px' }); DropDownTreeObj.appendTo('#' + id); function select(args) { if (args.action == "select") { return dotNetHelper.invokeMethodAsync('GetSelectedText', args.itemData.id); } } function onChange(args) { if (args.value.length == 0) { return dotNetHelper.invokeMethodAsync('TextCleared'); } } }</script> |
C#
objRef = DotNetObjectReference.Create(this); JSRuntime.InvokeAsync<object>("RenderDropDownTree", objRef, Accounts.Adapt<AccountDtoListItem[]>(), Id, Value, "name", "parentAccountId", Placeholder, Query).GetAwaiter(); StateHasChanged(); |
Is this possible?
Hi Albert,
Yes, you can pass queries from server to client using interop call. But at the client end, it needs to be a pure JavaScript query in order to retrieve data. Check the below code snippet.
|
// Set queries to filter and fetch remote data var query = new ej.data.Query().from('Employees').select('EmployeeID,FirstName,Title').take(5); |
If you want to set the field and data value in the query based on the passed value from the server, You can send the data value (Employee) and field values (EmployeeID, FirstName, and Title) as separate strings in the interop call from the server end and construct the query in the index.html page as shown in the above code. Please try the suggested way and get back to us if you need any further assistance.
Regards,
Indhumathy L