Select Item method do not show selected item

I use List Box to replace List View to make custom grid filter.

The whole code of filter component is the next (and a few css separately):

@typeparam T

@using Syncfusion.Blazor.Inputs

@using Syncfusion.Blazor.DropDowns

@inherits OwningComponentBase<ApplicationDbContext>


@if (DataSource != null)

{

    @if (DataSource.Count > 7 && !DataSource.Any(r => string.IsNullOrEmpty(r.GetPropertyValue(SearchHere)?.ToString()))) 

    {

        <div class="filter-search">

            <SfTextBox Placeholder="@PlaceHolder" Input="@OnInput" />

        </div>

    }

<SfListBox @ref="@FilterListBox" TValue="int?[]" TItem="T" DataSource="@FilterSource" CssClass="filter-list m-0">

    <ListBoxFieldSettings Text="@SearchHere" Value="@Id" />

    <ListBoxSelectionSettings Mode="SelectionMode.Single" />

    <ListBoxEvents TValue="int?[]" TItem="T" Created="@OnCreated" ValueChange="@OnSelected" />

    <ListBoxTemplates TItem="T">

        <ItemTemplate>

            <div class="e-list-wrapper">

                @((MarkupString)context.GetPropertyValue(ShowThis)?.ToString())

            </div>

        </ItemTemplate>

    </ListBoxTemplates>

</SfListBox>

}


@code {

    [Parameter]

    public string SearchHere { get; set; } = nameof(DropDownListItem.SearchHere);

    [Parameter]

    public string ShowThis { get; set; } = nameof(DropDownListItem.ShowThis);

    [Parameter]

    public string Id { get; set; } = nameof(DropDownListItem.Id);

    [Parameter]

    public string PlaceHolder { get; set; }

    [Parameter]

    public T NotSet { get; set; }

    [Parameter]

    public T Value { get; set; }

    [Parameter]

    public EventCallback<T> ValueChange { get; set; }

    [Parameter]

    public Func<ApplicationDbContext, Task<List<T>>> GetDataSource { get; set; }


    SfListBox<int?[], T> FilterListBox;


    private List<T> DataSource { get; set; }

    private List<T> FilterSource { get; set; }

    private bool IsCreated { get; set; }


    protected override async Task OnInitializedAsync()

    {

        DataSource = await GetDataSource(Service);

        FilterSource = NotSet == null ? DataSource : DataSource.Prepend(NotSet).ToList();

    }

    private void OnInput(InputEventArgs args)

    {

        FilterSource = DataSource.FindAll(r =>

            r.GetPropertyValue(SearchHere).ToString().Contains(args.Value, StringComparison.InvariantCultureIgnoreCase));

        if (NotSet != null) FilterSource = FilterSource.Prepend(NotSet).ToList();

    }

    private void OnCreated(object args)

    {

        IsCreated = true;

        if (Value != null)

            FilterListBox.SelectItems(new int?[] { (int?)Value.GetPropertyValue(Id) });

        else if (NotSet != null)

            FilterListBox.SelectItems(new int?[] { (int?)NotSet.GetPropertyValue(Id) });

    }

    private void OnSelected(ListBoxChangeEventArgs<int?[], T> args)

    {

        if (IsCreated || args.Items == null)

        {

            IsCreated = false;

            return;

        }

        T SelectedItem = args.Value == null ? args.Items.FirstOrDefault(r => r.GetPropertyValue(Id) == null) :

            args.Items.FirstOrDefault(r => args.Value.Contains((int?)r.GetPropertyValue(Id)));

        if (SelectedItem != null)

            ValueChange.InvokeAsync(SelectedItem);

    }

}

Everything works well, except one detail. When the Filter is opened and List Box Created, it should to show preselected Value. I to make it using  FilterListBox.SelectItems(new int?[] { (int?)Value.GetPropertyValue(Id) }); in OnCreated method. But it is not work. I tried also SelectItemsAsync, @bind-Value and many different parameters for SelectItems method: T, T[], Text property value, string[] { Text property value}, int?. 

What is the right way for programmatic selection when  TValue="int?[]" TItem="T"?


14 Replies

GK Gayathri KarunaiAnandam Syncfusion Team November 9, 2021 03:47 AM UTC

Hi Stanislav, 

We have checked your reported query. We need to validate more on this. So, we will update you the further details on November 10th, 2021. We appreciate your patience until then. 

Regards, 
Gayathri K 



GK Gayathri KarunaiAnandam Syncfusion Team November 10, 2021 06:45 PM UTC

Hi Stanislav, 

Thanks for the patience. 

We have validated your reported query and we can reproduce this issue in our end. We have confirmed this as an issue from our side. We have logged a bug report for this. You can track its status from the below feedback link. The fix will be provided in our patch release which will be scheduled on December 1st, 2021. 


We appreciate your patience until then. 

Regards, 
Gayathri K 



MJ Michel Jost November 17, 2021 02:55 PM UTC

We are facing the same problem in production. A hotfox would be very much appreciated.


Best regards,


Michel



GK Gayathri KarunaiAnandam Syncfusion Team November 18, 2021 10:48 AM UTC

Hi Michel, 

We have checked your requirement and we would like to let you know that we need to ensure more test cases for this fix. So, As promised we will include the fix in our weekly patch release which will be scheduled for December 1st ,2021 and we appreciate your patience until then. 

Regards, 
Gayathri K 



MJ Michel Jost December 1, 2021 02:07 PM UTC

Contrary to what was announced, the problem was not fixed with the update this week:

https://blazor.syncfusion.com/documentation/release-notes/19.3.56?type=all


Our customer relied on the problem being solved today.


A quick test from my side showed that the problem does not only occur with nullable int. It also happens with the non nullable type long as a value.


Please give me an update on when the issue will be fixed or please provide a workaround for this issue.


Regards,

Michel



GK Gayathri KarunaiAnandam Syncfusion Team December 3, 2021 03:24 PM UTC

Hi Stanislav,   
  
We are sorry for the delay.  
  
We are facing more complexity in fixing this issue. So, we will include this fix in our upcoming patch release which will be scheduled for December 15th ,2021 and we appreciate your patience until then. You can track its status from the below feedback link.  
  

We appreciate your patience until then.  
    
Regards,   
Gayathri K   



GK Gayathri KarunaiAnandam Syncfusion Team December 16, 2021 04:33 PM UTC

Hi Stanislav, 

We are sorry for the delay.  

We have already resolved the reported issue in our end. Currently, we are in Volume 4 2021 release phase, and the fix will be available in our Volume 4 release which will be scheduled on 20th December ,2021. 

We appreciate your patience until then.  

Regards,             
Gayathri K 



GK Gayathri KarunaiAnandam Syncfusion Team December 21, 2021 11:47 AM UTC

Hi Stanislav, 

We are glad to announce that our Essential Studio 2021 Volume 4 release v19.4.0.38  is rolled out and is available for download under the following link. 


Code snippet: 
 
<SfListBox TValue="int?[]" TItem="T" DataSource="@Vehicles" @ref="ListBoxObj" > 
  <ListBoxEvents TValue="int?[]" Created="created" TItem="T"></ListBoxEvents> 
     
    <ListBoxFieldSettings Text="Text" Value="Text" /> 
</SfListBox> 
 
@code { 
    SfListBox<int?[], T> ListBoxObj; 
    public List<T> Vehicles = new List<T> { 
        new T { Text = 1, Id = 01 }, 
        new T { Text = 2, Id = 02 }, 
        new T { Text = 3, Id = 03}, 
        new T { Text = 4, Id = 04}, 
        new T { Text = 5, Id = 05}, 
        new T { Text = 6, Id = 06 }, 
        new T { Text = 7, Id = 07}, 
        new T { Text = 8, Id = 08} 
    }; 
 
    public class T 
    { 
        public int? Text { get; set; } 
        public int? Id { get; set; } 
    } 
 
  
     public int?[] Value = new int?[] { 2 , 3  }; 
   
    private async Task created(object args) 
    { 
         
        await ListBoxObj.SelectItems(Value, true); 
           
    } 
 
} 
 

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 

Regards,           
Gayathri K 



SG Stanislav Gordenko December 25, 2021 12:47 PM UTC

I use TValue = int?[] because I have not only integer values, but also the null value to clear selection.

When I apply 

 await FilterListBox.SelectItems(new int?[] { null }, true); 

I get the null exception. Please, correct it, the null value should be selected.

Integer values works 



GK Gayathri KarunaiAnandam Syncfusion Team December 28, 2021 04:36 PM UTC

Hi Stanislav, 

We are able to replicate the reported issue. We need to validate more on the reported issue, so will update you the further details on December 30th, 2021. 

Regards, 
Gayathri K 



GK Gayathri KarunaiAnandam Syncfusion Team January 1, 2022 03:27 AM UTC

Hi Stanislav, 

We will include the fix for the issue in our upcoming patch release which is scheduled on January 12th, 2022 and we appreciate your patience until then. 


Regards, 
Gayathri K 



GK Gayathri KarunaiAnandam Syncfusion Team January 13, 2022 08:06 PM UTC

Hi Stanislav, 
  
We deeply regret for the inconvenience caused.   
  
We have fixed this issue and ensured all testcases. But we are unable to move this fix into previous patch release. We have created a custom patch for the reported issue and the same can be downloaded below link.  
  
  
So, we suggest following below steps then upgrade our Syncfusion custom packages.  
      
1.      Due to the old Browser/NuGet cache.   
3.      Outdated custom scripts referred in the application.   
      
Also, could you please ensure the problem after clearing the browser/NuGet cache or run the application using incognito window of the browser.      
  
Regards,  
Gayathri K 



SG Stanislav Gordenko January 13, 2022 09:19 PM UTC

Hi Gayathri,


I have updated your package and everything works well few days already. Thank you



GK Gayathri KarunaiAnandam Syncfusion Team January 17, 2022 05:39 AM UTC

Hi Stanislav,  

We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this. 

Regards, 
Gayathri K 


Loader.
Up arrow icon