How to template Child Items

Here's my class

SnippetSnippet
public class Activity : ActivityBase
    {
        public string Id { getset; }
        public string Name { getset; }
        public string FormattedDateTime => DateTime.ToString("dddd, dd MMM HH:mm:ss tt");
 
        public List<Act> Action { getset; } = new();
    }
 
    public class Act: ActivityBase
    {
    }
 
    public partial class ActivityBase
    {
        public string Title { getset; }
        public string Message { getset; }
        public DateTime DateTime { getset; }
    }

7 Replies 1 reply marked as answer

LD LeoLavanya Dhanaraj Syncfusion Team June 16, 2022 10:03 AM UTC

Hi Arrebatrans,


Greetings from Syncfusion support.


You can achieve template support for list items with the help of the Template property in the ListView component. To customize list items in the application, set the customized template string to the Template property. Refer to the below documentation for reference.


https://blazor.syncfusion.com/documentation/listview/customizing-templates#template


The ListView component supports Nested List items. To achieve list navigation, the child property should be defined for the nested list in the array of JSON. Refer to the below documentation.


Documentation : https://blazor.syncfusion.com/documentation/listview/nested-list


Demo : https://blazor.syncfusion.com/demos/listview/nested-list?theme=fluent


Kindly check whether the shared details helpful for you. Please get back to us if need any further assistance.


Regards,

Leo Lavanya Dhanaraj



AN Arrebatrans Nigeria replied to LeoLavanya Dhanaraj June 16, 2022 08:30 PM UTC

I would like to create a separate template for the Child item. 



LD LeoLavanya Dhanaraj Syncfusion Team June 17, 2022 01:49 PM UTC

Hi Arrebatrans,


We understand that you want a separate template for the child item. However, we need some additional time to validate the feasibility to achieve your requirement and we will update you with further details on June 22, 2022.


Please clarify whether you want to apply different styles to the parent and child items or change the entire HTML template structure for child. Please provide a screenshot of your expected requirement so that we can check the feasibility of achieving your scenario.


We appreciate your patience.


Regards,

Leo Lavanya Dhanaraj



AN Arrebatrans Nigeria June 17, 2022 09:13 PM UTC

For some reason i don't know I'm getting a casting exception on the UI when I add the Child to the template

Here's my code


Snippet
<SfListView Id="activity-list"
					DataSource="@activityCollection"
					CssClass="e-list-template"
					SortOrder="SortOrder.Ascending">
			<ListViewFieldSettings TValue="Activity" Id="Id" Text="Name" Child="Action"></ListViewFieldSettings>
			<ListViewTemplates TValue="Activity">
				<Template>
					<div class="e-list-wrapper e-list-multi-line e-list-avatar">
						@if (((context as Activity).Name) == "Bitfinex")
						{
							<span class="image01 e-avatar e-avatar-circle"> </span>
						}
						else if (((context as Activity).Name) == "Binance")
						{
							<span class="image02 e-avatar e-avatar-circle"> </span>
						}
						else
						{
							<span class="activity-icon e-avatar e-avatar-circle">sc</span>
						}
						<span class="e-list-item-header">@((context as Activity).Title)</span>
						<span class="e-list-content">@((context as Activity).Message)</span>
						<span class="e-list-content">@((context as Activity).FormattedDate)</span>
					</div>
				</Template>
			</ListViewTemplates>
		</SfListView>



Snippet
protected List<Activity>? activityCollection = new();
Snippet
public class Activity : ActivityBase
    {
        public string Id { getset; }
        public string Name { getset; }
        public string FormattedDate => DateTime.ToString("dddd, dd MMM");
        public List<Act> Action { getset; } = new();
    }
 
    public class Act : ActivityBase
    {
        public string FormattedTime => DateTime.ToString("HH:mm:ss tt");
    }
 
    public partial class ActivityBase
    {
        public string Title { getset; }
        public string Message { getset; }
        public DateTime DateTime { getset; }
    }


LD LeoLavanya Dhanaraj Syncfusion Team June 21, 2022 06:57 AM UTC

Hi Arrebatrans,


From your shared code snippet, we understand that you are facing a casting exception. We suspect that the issue is due to the use of more than one class in your sample. Even in our Nested List support, we have bound only one parent class to bind the property for both the root and child list items. For your reference, we have attached the sample with the single parent class. Also, refer to the below documentation.


https://blazor.syncfusion.com/documentation/listview/nested-list


https://www.syncfusion.com/downloads/support/directtrac/general/ze/ListViewSample1319124675.zip


Please check the attached sample and get back to us if you need any further assistance.


Regards,

Leo Lavanya Dhanaraj



AN Arrebatrans Nigeria June 24, 2022 03:47 PM UTC

Thank you for your response,

I was able to sort out my code and UI through the samples

I realize the limitation with SfListView and worked around it by combining it with SfAccordion

Screenshot 2022-06-24 164623.png


Marked as answer

IL Indhumathy Loganathan Syncfusion Team June 27, 2022 06:24 AM UTC

Hi Arrebatrans,


Thanks for the update.


We are glad to know that your issue has been resolved. Please get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon