Conditional CSS in each card

I would like to format each card uniquely, i.e. having unique css for each card's header, content. Is there a way to do so? For example, cards that have "underline=true" in the database will have texts with underline decoration.


3 Replies 1 reply marked as answer

RK Revanth Krishnan Syncfusion Team November 12, 2021 01:12 PM UTC

Hi Desmond, 
 
 
Greetings from Syncfusion support. 
 
 
We have validated your query “I would like to format each card uniquely, i.e. having unique CSS for each card's header, content. Is there a way to do so? For example, cards that have "underline=true" in the database will have texts with underline decoration.” 
 
Your requirement to format each card uniquely can be achieved by using the card template. We have prepared a sample where based on the data field in the card the class is added which is then styled using CSS. 
 
Code Snippet: 
<SfKanban TValue="TasksModel" KeyField="Status" DataSource="Tasks"> 
    . . . 
    <KanbanCardSettings HeaderField="Id" ContentField="Summary"> 
        <Template> 
            @{ 
                TasksModel data = (TasksModel)context; 
                <div class="e-card-content"> 
                    <table class="card-template-wrap"> 
                        <tbody> 
                            . . . 
                            <tr class="details @( @data.Underline ? "contentUnderline" : "content")"> 
                                <td class="CardHeader">Summary:</td> 
                                <td>@data.Summary</td> 
                            </tr> 
                        </tbody> 
                    </table> 
                </div> 
            } 
        </Template> 
    </KanbanCardSettings> 
</SfKanban> 
 
<style type="text/css"> 
    .contentUnderline { 
        text-decoration: underline; 
        text-decoration-color: red; 
        text-decoration-style: double; 
    } 
 
    . . . 
</style> 
 
@code { 
    public class TasksModel 
    { 
        public bool Underline { get; set; } 
        public string Id { get; set; } 
        public string Title { get; set; } 
        public string Status { get; set; } 
        public string Summary { get; set; } 
        public string Type { get; set; } 
        public string Priority { get; set; } 
        public string Assignee { get; set; } 
    } 
 
    public List<TasksModel> Tasks = new List<TasksModel>() 
   { 
        new TasksModel { Underline = true, Id = "Task 1", Title = "BLAZ-29001", Status = "Open", Summary = "Analyze the new requirements gathered from the customer.", Assignee = "Nancy Davloio", Type = "Story", Priority = "Low" }, 
        new TasksModel { Underline = true, Id = "Task 2", Title = "BLAZ-29002", Status = "InProgress", Summary = "Improve application performance", Assignee = "Andrew Fuller", Type = "Improvement", Priority = "Normal" }, 
         
    }; 
} 
 
 
 
Please check the above code snippet, documentation, and sample and let us know if it satisfies your requirement. 
 
Regards, 
Revanth 


Marked as answer

DE desmond November 13, 2021 10:18 AM UTC

Yes, you are right, thanks for the tip.



IS Indrajith Srinivasan Syncfusion Team November 15, 2021 12:06 PM UTC

Hi Desmond,

Welcome,

Please get back to us if you need any further assistance.

Regards,
Indrajith


Loader.
Up arrow icon