curious
curious

Reputation: 109

QuickGrid Boolean Checkbox Column?

Is there a way to add a Boolean column to a Blazor QuickGrid that can be 'formatted' so that it appears in the grid as a Checkbox? To be clear, my question is specifically related to Blazor QuickGrid capability. Fwiw, I know how to handle Boolean values in other types of 'grids'.

For what it's worth, I've looked around quite a bit and haven't found any QuickGrid examples of this. QuickGrid will indeed successfully display the words "True" and "False" to represent Boolean values... and I'm grateful for that.. but I haven't found a way to represent those values as anything but those two strings.

Upvotes: 3

Views: 1858

Answers (2)

Robin Wilson
Robin Wilson

Reputation: 390

I have just done this using a template column and made the checkbox a Bootstrap formatted one:

<TemplateColumn Title="Is Enabled" Sortable="true" SortBy="GridSort<MessageTemplateModel>.ByDescending(x => x.IsEnabled)">
    <button type="button" class="btn @(context!.IsEnabled == true? "btn-primary" : "btn-outline-primary")"><i class="@(context!.IsEnabled == null? "fa-regular fa-square-minus" : context!.IsEnabled == true? "fa-solid fa-square-check" : "fa-regular fa-square")"></i></button>
</TemplateColumn>

This is how it looks: Example of checkboxes formatted using Bootstrap

Upvotes: 1

Alamakanambra
Alamakanambra

Reputation: 7881

Minimal example:

<QuickGrid TGridItem="MyClass" Items="@myClasses">
    <TemplateColumn >
        @if(context.BoolVal)
        {
         <input type="checkbox" checked/>
        }
        else
        {
            <input type="checkbox" />
        }
    </TemplateColumn>
</QuickGrid>

@code{
    List<MyClass> myList = [new(),new(){BoolVal = true}];
    IQueryable<MyClass> myClasses => myList.AsQueryable();
    public class MyClass
    {
        public bool BoolVal { get; set; }
    }
}

You have to take care about the checkboxes being "read-only", style it, etc..

Upvotes: 5

Related Questions