Search code examples
blazorquickgrid

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.


Solution

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