Display number of items filtered in listview (count)

Hi,


Is it possible to display the number of filtered items in the listview while using the 

DataSource.Filter method (as shown here: https://help.syncfusion.com/xamarin/listview/filtering)


So we would be able to display the following when filtered: Showing 5 items of 100


We tried viewing this https://www.syncfusion.com/forums/139916/listview-displays-incorrect-number-of-items but receive a 404 when opening the page.


1 Reply

LN Lakshmi Natarajan Syncfusion Team January 11, 2022 01:25 PM UTC

Hi Malcolm, 
 
You can achieve your requirement by getting the filtered count from the SfListView.DataSource.DisplayItems. Please refer to the following code snippets for more reference, 
 
ViewModel: Create a property to show the filtered items count 
public class SortingFilteringViewModel : INotifyPropertyChanged 
{ 
    … 
    public SortingFilteringViewModel() 
    { 
        AddItemDetails(); 
 
        Count = Items.Count; 
    } 
 
    public int Count 
    { 
        get { return count; } 
        set { count = value; OnPropertyChanged("Count"); } 
    } 
} 
 
XAML: Bind the Count property. And using converter, you can format the text based on your requirement. 
<Grid BackgroundColor="DarkGoldenrod" Grid.Row="1"> 
    <Label Text="{Binding Count, Converter={StaticResource HeaderTextConverter}, 
    ConverterParameter={x:Reference viewModel}}" 
        HorizontalOptions="Center" VerticalOptions="Center"  
        FontAttributes="Bold" FontSize="Caption" TextColor="White"/> 
</Grid> 
 
Behavior: In the TextChanged event, update the count property after filter. 
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e) 
{ 
            searchBar = (sender as SearchBar); 
            sortingFilteringViewModel = searchBar.BindingContext as SortingFilteringViewModel; 
 
            if (ListView.DataSource != null) 
            { 
                        ListView.DataSource.Filter = FilterContacts; 
                        ListView.DataSource.RefreshFilter(); 
            } 
            ListView.RefreshView(); 
            sortingFilteringViewModel.Count = ListView.DataSource.DisplayItems.Count; 
} 
 
We have prepared a sample to achieve your requirement and attached in the following link,  
 
Screenshot 
 
 
Regarding 404 error, we are checking the same with our internal team. We will let you know when its fixed. 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 
 


Loader.
Up arrow icon