Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 321
curious Avatar asked Jun 27 '26 15:06

curious


2 Answers

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..

like image 138
Alamakanambra Avatar answered Jun 30 '26 10:06

Alamakanambra


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

like image 38
Robin Wilson Avatar answered Jun 30 '26 10:06

Robin Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!