How to make a custom input box/filter values for a column

QUESTION 1:
Hi, I want to create a drop-down menu under the 'Status' column that has values of { Active, Inactive }. So, when user edits a record, they can select 'Active' or 'Inactive'.
Currently, my data table stores 'Active = true', 'Inactive = false' so I need to be able to convert bool into those string values. How do I create a custom drop-down box that has options of 'Active = true', 'Inactive = false'?

QUESTION 2:
I want to create a custom filter for 'Status' column that reflects options for 'Active' / 'Inactive' and not 'True' / 'False'. How do I create a custom filter with these values?

.'razor' 


Attachment: Status_column_values_116aca9f.zip

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team May 12, 2021 02:39 PM UTC

Hi Kenney, 

Greetings from Syncfusion. 
 
Query: I want to create a drop-down menu under the 'Status' column that has values of { Active, Inactive }. So, when user edits a record, they can select 'Active' or 'Inactive'. How do I create a custom drop-down box that has options of 'Active = true', 'Inactive = false'? 

We have validated your query and you want to render custom dropdown list(shown string values instead of boolean values) while editing the Boolean type column. You can achieve your requirement by using EditTemplate.  Here, we have rendered a dropdown list(with string values shown) in Boolean column while editing. Find the below code snippets and sample for your reference. 

 
 
<SfGrid DataSource="@OrderData" AllowFiltering="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings> 
    <GridColumns> 
        . . . 
        <GridColumn Field=@nameof(Order.Verified) HeaderText="Status" TextAlign="TextAlign.Center" Width="120"> 
            . . . 
            <EditTemplate>   @*rendered a custom dropdown while editing*@  
                <SfDropDownList ID="Verified" TValue="bool" TItem="Status" @bind-Value="@((context as Order).Verified)" DataSource="@LocalData"> 
                    <DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings> 
                </SfDropDownList> 
            </EditTemplate> 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
 
@code{ 
    . . . 
    public class Status 
    { 
        public bool ID { get; set; } 
        public string Text { get; set; } 
    } 
    List<Status> LocalData = new List<Status> { 
        new Status() { ID= true, Text= "Active" }, 
        new Status() { ID= false, Text= "InActive" }, 
  }; 
 
} 
 
 
Query: I want to create a custom filter for 'Status' column that reflects options for 'Active' / 'Inactive' and not 'True' / 'False'. How do I create a custom filter with these values?  

You want to show custom values(Active and InActive instead of True and False values) in Filter dialog. You can achieve your requirement by using FilterItemTemplate. Find the below code snippets and sample for your reference. 

<GridColumn Field=@nameof(Order.Verified) HeaderText="Status" TextAlign="TextAlign.Center" Width="120"> 
            <Template> 
                . . . 
            </Template> 
            <FilterItemTemplate> 
                @*display customized values in filter dialog using FilterItemTemplate*@ 
                @{ 
                    var cont = context as FilterItemTemplateContext; 
                    if (cont.Value.ToString() == "True") 
                    { 
                        <div>Active</div> 
                    } 
                    else 
                    { 
                        <div>InActive</div> 
                    } 
                } 
            </FilterItemTemplate>        </GridColumn> 


Reference: 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer

KP Kenney Phan May 13, 2021 05:21 PM UTC

Hi, thank you for your help.

It works, but when I go to use the search bar for the filter on 'Status', it breaks because it cannot convert string to bool.

How can I use the filter search bar such that it will compare the searched string with 'Active' & 'Inactive'?

If not possible, how can I disable the search bar on the filter for 'Status' column? 

Thanks


JP Jeevakanth Palaniappan Syncfusion Team May 14, 2021 06:50 AM UTC

Hi Kenney, 
 
It is not possible to resolve the error thrown during searching since the type of data is different in the datasource. So we suggest you to set Menu filter type of that particular column and you  can filter the values by using the dropdown component. Please refer the below code snippet, documentation and sample for your reference. 

<GridColumn Field=@nameof(Order.Verified) FilterSettings="@(new FilterSettings{Type = Syncfusion.Blazor.Grids.FilterType.Menu })" HeaderText="Status" TextAlign="TextAlign.Center" Width="120"> 
.. 
.. 
            <FilterTemplate> 
                <SfDropDownList ID="Verified" @bind-Value="@((context as PredicateModel<bool>).Value)" TItem="Status" TValue="bool" DataSource="@(LocalData)"> 
                    <DropDownListFieldSettings Value="ID" Text="Text"></DropDownListFieldSettings> 
                </SfDropDownList> 
            </FilterTemplate> 
.. 
.. 
        </GridColumn> 



Please get back to us if you have any other queries, 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon