[index.razor]
@using Syncfusion.Blazor.DropDowns
<SfMultiSelect ID="MultiSelect" @bind-Value="@ClassIDs" TValue="string[]" Placeholder="Select Nice Classes" Mode="@VisualMode.CheckBox"
DataSource="@Country" ShowSelectAll="false" EnableSelectionOrder="true"
ShowDropDownIcon="true" FilterBarPlaceholder="Nice Classes" >
<MultiSelectEvents TValue="string[]" Opened="PopupOpen"></MultiSelectEvents>
<MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>
</SfMultiSelect>
@code {
[Inject]
protected IJSRuntime JsRuntime { get; set; }
public string[] ClassIDs { get; set; } = new string[] { "CA", "CM" };
public class Countries
{
public string Name { get; set; }
public string Code { get; set; }
}
private List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = "AU" },
new Countries() { Name = "Bermuda", Code = "BM" },
new Countries() { Name = "Canada", Code = "CA" },
new Countries() { Name = "Cameroon", Code = "CM" },
new Countries() { Name = "Denmark", Code = "DK" },
new Countries() { Name = "France", Code = "FR" },
new Countries() { Name = "Finland", Code = "FI" },
new Countries() { Name = "Germany", Code = "DE" }
};
public void PopupOpen(Syncfusion.Blazor.DropDowns.PopupEventArgs args)
{
JsRuntime.InvokeVoidAsync("OnPopupOpen", "MultiSelect");
}
}
[daterange.js]
window.OnPopupOpen = (id) => {
console.log(id);
var instances = document.getElementById(id).ej2_instances[0];
var LIElement = instances.popupObj.element.getElementsByClassName('e-list-item');
var LICount = LIElement.length;
for (var item = 0; item < LICount; item++) {
var value = LIElement[item].getAttribute('data-value');
if (instances.value && (instances.value.length > 0) && !instances.value.includes(value)) {
LIElement[item].classList.add('e-disabled');
}
}
}
[_Host.Cshtml]
<script src="~/daterange.js"></script>
|
Trying to make it work but, for me, I cant find the ej2_instances[0] from the document.getElementById(id)
What am I doing wrong?
@inject IJSRuntime JS
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Buttons
<SfMultiSelect TValue="string[]" TItem="Countries" ID="MultiSelect" @bind-Value="@ClassIDs" TValue="string[]" Placeholder="Select Nice Classes" Mode="@VisualMode.CheckBox"
DataSource="@Country" ShowSelectAll="false" EnableSelectionOrder="true"
ShowDropDownIcon="true" FilterBarPlaceholder="Nice Classes" >
<MultiSelectEvents TValue="string[]" TItem="Countries" Opened="PopupOpen"></MultiSelectEvents>
<MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings>
</SfMultiSelect>
@code {
public string[] ClassIDs { get; set; } = new string[] { "CA", "CM" };
public class Countries
{
public string Name { get; set; }
public string Code { get; set; }
}
private List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = "AU" },
new Countries() { Name = "Bermuda", Code = "BM" },
new Countries() { Name = "Canada", Code = "CA" },
new Countries() { Name = "Cameroon", Code = "CM" },
new Countries() { Name = "Denmark", Code = "DK" },
new Countries() { Name = "France", Code = "FR" },
new Countries() { Name = "Finland", Code = "FI" },
new Countries() { Name = "Germany", Code = "DE" }
};
public class JsonData
{
public string id { get; set; }
public string[] items { get; set; }
}
public async Task PopupOpen(Syncfusion.Blazor.DropDowns.PopupEventArgs args)
{
JsonData data = new JsonData();
data.id = "MultiSelect";
data.items = ClassIDs;
await JS.InvokeVoidAsync("OnPopupOpen", data);
}
} |
<script>
window.OnPopupOpen = (args) => {
var proxy = args;
setTimeout(()=>{
var LIElement = document.getElementById(proxy.id+"_popup").getElementsByClassName('e-list-item');
var LICount = LIElement.length;
for (var item = 0; item < LICount; item++) {
var value = LIElement[item].getAttribute('data-value');
if (args.items && (args.items.length > 0) && !args.items.includes(value)) {
LIElement[item].classList.add('e-disabled');
}
}
},100);
}
</script> |