Problem filtering an ordered list
Hi,
I'm not able to filter a dropdownlist, whose datasource is an ordered list.
The problem may be in the list 'OrderBy', but I really don't understand why ...
Below is the code I am using.
Can you help, please?
Thanks,
Fausto
<div class="dropdown m-3">
<SfDropDownList ID="Task_PatientId"
@ref="ddlPatients"
TValue="int"
TItem="Patient_Minimized" Width="400px"
AllowFiltering="true"
FilterBarPlaceholder="Doente"
FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"
ShowClearButton="true"
DataSource="@patientList" Placeholder="Doente"
@bind-Value="@selectedTask.IdCliente">
<DropDownListTemplates TItem="Patient_Minimized"></DropDownListTemplates>
<DropDownListEvents TValue="int"
TItem="Patient_Minimized"
ValueChange="onChangePatient"
Filtering="OnFilter">
</DropDownListEvents>
<DropDownListFieldSettings Text="Nome" Value="IdCliente"></DropDownListFieldSettings>
</SfDropDownList>
</div>
// Code
protected IEnumerable<Patient_Minimized> patientList; // = new List<Patient_Minimized>();
protected SfDropDownList<int, Patient_Minimized> ddlPatients;
protected override async Task OnInitializedAsync()
{
//CreateDummyData();
CurrentUser = (await authenticationStateTask).User;
var user = await _UserManager.FindByNameAsync(CurrentUser.Identity.Name);
IsUserDoctor = user.IsDoctor;
doctorID = user.CodMedico;
tasksList = await GetAllTasksAsync();
patientList = await GetDoctorPatients(doctorID);
}
protected async Task<IEnumerable<Patient_Minimized>> GetDoctorPatients(int doctorCode)
{
var patients = await patientsService.FindDoctorPatientsAsync(doctorCode); // list comes encrypted
if (!output.Any() || output == null)
{
sErrorMsgs = new List<string>() { "Médico não tem doentes registados. Verifique, p.f." }; // Doctor has no patients assigned...
ErrorVisibility = true;
EditTaskDialogVisibility = false;
}
List<Patient_Minimized> patientListDecoded = new List<Patient_Minimized>();
foreach (var patient in patients)
{
patientListDecoded.Add(new Patient_Minimized()
{
IdCliente = patient.IdCliente, // Patient ID
Nome = _securityProvider.Decrypt(patient.Nome) // Patient Name
});
}
//List decoded and ordered by patient name
// TODO -- after ordering, patient dropdown does not allow search
return patientListDecoded.OrderBy(p => p.Nome);
}
protected async Task OnFilter(FilteringEventArgs args)
{
args.PreventDefaultAction = true;
var query = new Query().Where(new WhereFilter() { Field = "Nome", Operator = "contains", value = args.Text, IgnoreCase = true });
query = !string.IsNullOrEmpty(args.Text) ? query : new Query();
await ddlPatients.Filter(patientList, query);
}
SIGN IN To post a reply.
3 Replies
Hi,I'm not able to filter a dropdownlist, whose datasource is an ordered list.The problem may be in the list 'OrderBy', but I really don't understand why ...Below is the code I am using.Can you help, please?Thanks,Fausto<div class="dropdown m-3"><SfDropDownList ID="Task_PatientId"@ref="ddlPatients"TValue="int"TItem="Patient_Minimized" Width="400px"AllowFiltering="true"FilterBarPlaceholder="Doente"FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"ShowClearButton="true"DataSource="@patientList" Placeholder="Doente"@bind-Value="@selectedTask.IdCliente"><DropDownListTemplates TItem="Patient_Minimized"></DropDownListTemplates><DropDownListEvents TValue="int"TItem="Patient_Minimized"ValueChange="onChangePatient"Filtering="OnFilter"></DropDownListEvents><DropDownListFieldSettings Text="Nome" Value="IdCliente"></DropDownListFieldSettings></SfDropDownList></div>// Codeprotected IEnumerable<Patient_Minimized> patientList; // = new List<Patient_Minimized>();protected SfDropDownList<int, Patient_Minimized> ddlPatients;protected override async Task OnInitializedAsync(){//CreateDummyData();CurrentUser = (await authenticationStateTask).User;var user = await _UserManager.FindByNameAsync(CurrentUser.Identity.Name);IsUserDoctor = user.IsDoctor;doctorID = user.CodMedico;tasksList = await GetAllTasksAsync();patientList = await GetDoctorPatients(doctorID);}protected async Task<IEnumerable<Patient_Minimized>> GetDoctorPatients(int doctorCode){var patients = await patientsService.FindDoctorPatientsAsync(doctorCode); // list comes encryptedif (!output.Any() || output == null){sErrorMsgs = new List<string>() { "Médico não tem doentes registados. Verifique, p.f." }; // Doctor has no patients assigned...ErrorVisibility = true;EditTaskDialogVisibility = false;}List<Patient_Minimized> patientListDecoded = new List<Patient_Minimized>();foreach (var patient in patients){patientListDecoded.Add(new Patient_Minimized(){IdCliente = patient.IdCliente, // Patient IDNome = _securityProvider.Decrypt(patient.Nome) // Patient Name});}//List decoded and ordered by patient name// TODO -- after ordering, patient dropdown does not allow searchreturn patientListDecoded.OrderBy(p => p.Nome);}protected async Task OnFilter(FilteringEventArgs args){args.PreventDefaultAction = true;var query = new Query().Where(new WhereFilter() { Field = "Nome", Operator = "contains", value = args.Text, IgnoreCase = true });query = !string.IsNullOrEmpty(args.Text) ? query : new Query();await ddlPatients.Filter(patientList, query);}
Errata:
In the code, where it says:
if (!output.Any() || output == null)
should be
if (!patients.Any() || patients == null)
Hi,I'm not able to filter a dropdownlist, whose datasource is an ordered list.The problem may be in the list 'OrderBy', but I really don't understand why ...Below is the code I am using.Can you help, please?Thanks,Fausto<div class="dropdown m-3"><SfDropDownList ID="Task_PatientId"@ref="ddlPatients"TValue="int"TItem="Patient_Minimized" Width="400px"AllowFiltering="true"FilterBarPlaceholder="Doente"FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains"ShowClearButton="true"DataSource="@patientList" Placeholder="Doente"@bind-Value="@selectedTask.IdCliente"><DropDownListTemplates TItem="Patient_Minimized"></DropDownListTemplates><DropDownListEvents TValue="int"TItem="Patient_Minimized"ValueChange="onChangePatient"Filtering="OnFilter"></DropDownListEvents><DropDownListFieldSettings Text="Nome" Value="IdCliente"></DropDownListFieldSettings></SfDropDownList></div>// Codeprotected IEnumerable<Patient_Minimized> patientList; // = new List<Patient_Minimized>();protected SfDropDownList<int, Patient_Minimized> ddlPatients;protected override async Task OnInitializedAsync(){//CreateDummyData();CurrentUser = (await authenticationStateTask).User;var user = await _UserManager.FindByNameAsync(CurrentUser.Identity.Name);IsUserDoctor = user.IsDoctor;doctorID = user.CodMedico;tasksList = await GetAllTasksAsync();patientList = await GetDoctorPatients(doctorID);}protected async Task<IEnumerable<Patient_Minimized>> GetDoctorPatients(int doctorCode){var patients = await patientsService.FindDoctorPatientsAsync(doctorCode); // list comes encryptedif (!output.Any() || output == null){sErrorMsgs = new List<string>() { "Médico não tem doentes registados. Verifique, p.f." }; // Doctor has no patients assigned...ErrorVisibility = true;EditTaskDialogVisibility = false;}List<Patient_Minimized> patientListDecoded = new List<Patient_Minimized>();foreach (var patient in patients){patientListDecoded.Add(new Patient_Minimized(){IdCliente = patient.IdCliente, // Patient IDNome = _securityProvider.Decrypt(patient.Nome) // Patient Name});}//List decoded and ordered by patient name// TODO -- after ordering, patient dropdown does not allow searchreturn patientListDecoded.OrderBy(p => p.Nome);}protected async Task OnFilter(FilteringEventArgs args){args.PreventDefaultAction = true;var query = new Query().Where(new WhereFilter() { Field = "Nome", Operator = "contains", value = args.Text, IgnoreCase = true });query = !string.IsNullOrEmpty(args.Text) ? query : new Query();await ddlPatients.Filter(patientList, query);}
Image attached
Attachment: PatientList_201d9922.rar
VS
Vignesh Srinivasan
Syncfusion Team
January 10, 2021 03:51 PM UTC
Hi Fausto,
Greetings from Syncfusion support.
We made sample based on your requirement. We cannot able to replicate your issue. Please find the sample below.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DropdownListAsyncData-635148596
Kindly check with the above sample. If your still facing the issue, could you please replicate the issue in the given sample to proceed further from our end.
Regards,
Vignesh Srinivasan.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
FA Fausto
- Jan 3, 2021 08:51 PM UTC
- Jan 10, 2021 03:51 PM UTC