We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

List of cards in a grid from a Enumerable List

I have a list of objects that I want to display as a list of cards in a grid type format. How do you do that with the SF Blazor controls?

4 Replies

DG Durga Gopalakrishnan Syncfusion Team May 6, 2020 04:16 PM UTC

Hi Jim, 
 
Greetings from Syncfusion. 
 
We have analyzed your query. We suggest you to create a card for list of objects in grid format using bootstrap CSS. We have prepared sample for your reference. Please check with the below code snippet and sample. You can style each card based on your requirement.  
 
Code Snippet 
 
<div class="row e-card-layout" style="text-align:center;"> 
        @foreach (var data in ListData) 
        { 
            <div class="col-lg-3 col-md-3 col-sm-6"> 
                <SfCard> 
                    <CardHeader Title=@data.Title SubTitle=@data.Subtitle /> 
                    <CardContent Content=@data.Content /> 
                </SfCard> 
            </div> 
        } 
    </div> 
@code{ 
    List<DataModel> ListData = new List<DataModel>(); 
    protected override void OnInitialized() 
    { 
        base.OnInitialized(); 
        ListData.Add(new DataModel 
        { 
            Title = "ASP.NET MVC", 
            Subtitle = "Nick Harrison", 
            Content = "ASP.NET Model View Controller design pattern to keep the data, views, and logic clearly separated in apps.", 
        }); 
       //…. 
} 
 
 
Screenshot 
 
 
Sample 
 
Please revert us, if you have any concerns. 
 
Regards, 
Durga G 



ED Eduardo February 16, 2022 12:48 AM UTC

Greetings!

Is there a way to display a list of cards with lazy loading?

For example: I have enough data to display in 100 cards, but I want to load only 20, and the rest will appear as I scroll down the page.



BS Buvana Sathasivam Syncfusion Team February 17, 2022 05:21 PM UTC

Hi Consensu, 
 
Currently, we are validating your reported query. We will update you with further details on or before February 21, 2022. 
 
Regards, 
Buvana S 



VJ Vinitha Jeyakumar Syncfusion Team February 24, 2022 10:05 AM UTC

Hi Consensu,


We have created a sample as per your requirement using virtualize concept to display 10 cards on initial loading and the remaining will appear when we scroll down the page. please check the code below,

Code snippet:
<div style="height:500px;overflow-y:scroll">  
    <table class="table">  
        <thead>  
            <tr>  
                <th>Employee Id</th>  
                <th>Employee Name</th>  
                <th>Role</th>  
            </tr>  
        </thead>  
        <tbody>  
            <Virtualize ItemsProvider="LoadEmployeeDetails" Context="employee">  
                <ItemContent>  
                    <tr>  
                        <td>  
                            <SfCard>  
                                  
                                <CardHeader>Sample Card</CardHeader>  
                                <CardContent>@employee.EmployeeId</CardContent>  
                            </SfCard>  
                        </td>  
                        <td>  
                            <SfCard>  
                                  
                                <CardHeader>Sample Card</CardHeader>  
                                    <CardContent>@employee.Name</CardContent>  
                            </SfCard>  
                        </td>  
                        <td>  
                            <SfCard>  
                                  
                                <CardHeader>Sample Card</CardHeader>  
                                <CardContent>@employee.Role</CardContent>  
                            </SfCard>  
                        </td>  
                    </tr>  
                </ItemContent>  
                <Placeholder>  
                    <p>Loading employee details...</p>  
                </Placeholder>  
            </Virtualize>  
        </tbody>  
    </table>  
    </div>  
  
    @code {  
        private List<EmployeeDetails> employees;  
  
        protected override async Task OnInitializedAsync()  
        {  
            employees = await GetEmployeeDetails();  
        }  
        private async ValueTask<ItemsProviderResult<EmployeeDetails>> LoadEmployeeDetails(ItemsProviderRequest request)  
        {  
            var employees = await GetEmployeeDetails();  
            return new ItemsProviderResult<EmployeeDetails>(employees.Skip(request.StartIndex).Take(request.Count), employees.Count());  
        }  
        private async Task<List<EmployeeDetails>> GetEmployeeDetails()  
        {  
            List<EmployeeDetails> employeeList = new List<EmployeeDetails>();  
            List<string> roleList = new List<string>() { ".Net Developer", "Testing Engineer", "Graphic Designer", "Technical Writer", "Support Coordinator" };  
            int roleArrayIndex = 0;  
            int tempCount = 0;  
            int employeeDataCount = 100;  
  
            for (int i = 1; i <= employeeDataCount; i++)  
            {  
                if (i > tempCount + employeeDataCount / roleList.Count())  
                {  
                    roleArrayIndex++;  
                    tempCount = i - 1;  
                }  
  
                var employeeDetails = new EmployeeDetails()  
                {  
                    EmployeeId = i,  
                    Name = "Employee " + i.ToString(),  
                    Role = roleList[roleArrayIndex]  
                };  
  
                employeeList.Add(employeeDetails);  
            }  
            return await Task.FromResult(employeeList);  
        }  
  
        public class EmployeeDetails  
        {  
            public int EmployeeId { get; set; }  
  
            public string Name { get; set; }  
  
            public string Role { get; set; }  
        }  
  
    }  
<style>  
    .e-card {  
        background-color: antiquewhite;  
        height: 300px;  
    }  
</style>  

 


To know more details about component virtulization in blazor, plrease check the below link,


Regards,
Vinitha


Loader.
Live Chat Icon For mobile
Up arrow icon