简体   繁体   English

Telerik 网格过滤器选项,用于带 blazor 的下拉列表

[英]Telerik grid filter option for dropdown with blazor

Hello I'm working on blazor server side application, I've displayed data into GRID.您好,我正在开发 blazor 服务器端应用程序,我已将数据显示到 GRID 中。 and I've provided filter for columns wherever needed.我在需要的地方为列提供了过滤器。 We can show/hide filter option with Filterable="true/false" value.我们可以使用 Filterable="true/false" 值显示/隐藏过滤器选项。

My concern is quite different.我的担忧完全不同。 I'm having tables named Invoice , Client and ClientGroup我有名为InvoiceClientClientGroup 的表

Here Client and ClientGroup tables contains Id/value fields, say dropdown data.这里ClientClientGroup表包含 Id/value 字段,比如下拉数据。 And Invoice table have reference of ClientId and ClientGroupId having foreign key reference并且发票表有参考的ClientIdClientGroupId外键参考

I'm displaying Invoice table data into Telerik Grid with blazor我正在使用 blazor 将发票表数据显示到Telerik Grid 中

Below is my sample code to display ClientGroup data into Grid but filter option is not working because model have int property.下面是我的示例代码,用于将ClientGroup数据显示到 Grid 但过滤器选项不起作用,因为模型具有 int 属性。

<GridColumn Field="@(nameof(InvoiceModel.ClientGroupId))" Title="ClientGroup" Width="300px" Filterable="true">

            <Template>
                @{
                    var data = context as InvoiceModel;
                    var clientGroup = StaticData.GetClientGroupName(data.AffilatedGroup);

                    if (data.IsDisplayClientGroupDropdown)
                    {
                        <select class="form-control small-input-financial-view drp-finanz w-100"
                                id="Medienart">
                            @foreach (var item in ClientList)
                            {
                                if (item.ClienGrouptName == clientGroup)
                                {
                                    <option selected value="@item.ClientGroupId">
                                        @item.ClienGrouptName
                                    </option>
                                }
                                else
                                {
                                    <option value="@item.ClientGroupId">
                                        @item.ClienGrouptName
                                    </option>
                                }
                            }
                        </select>
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(clientGroup))
                        {
                            <a href="javascript:;"
                               title="No clientGroup data found"
                               class="maximum-cher-div">
                                No clientGroup data found
                            </a>
                        }
                        else
                        {
                            <a href="javascript:;"
                               title="@clientGroup"
                               class="maximum-cher-div">
                                @clientGroup
                            </a>
                        }

                    }

                }
            </Template>
        </GridColumn>

I did some research for dropdown values filter but I didn't get any appropriate solution.我对下拉值过滤器进行了一些研究,但没有得到任何合适的解决方案。 any type of the help would be appreciated.任何类型的帮助将不胜感激。

If your ClientGroup table does not change at runtime, the easiest way would be to create an enum equivalent for your ClientGroups:如果您的 ClientGroup 表在运行时没有改变,最简单的方法是为您的 ClientGroup 创建一个等效的枚举:

public enum ClientGroupEnum
{
   Group1 = 1,
   Group2 = 2,
   ...
}

In your InvoiceModel you can then use a ClientGroupEnum Property instead of the ClientGroupId Property.在您的 InvoiceModel 中,您可以使用 ClientGroupEnum 属性而不是 ClientGroupId 属性。

In the grid you can then add the following column:在网格中,您可以添加以下列:

<GridColumn Field="@(nameof(InvoiceModel.ClientGroupEnum))" Title="ClientGroup" Width="300px" Filterable="true"/>

Then you don't need a Template at all.那么你根本不需要模板。 In the column you will then see the textual representation of the enum value (eg Group1) and in the filter you will be able to select a value from a dropdown containing all textual representations of your enum.在列中,您将看到枚举值的文本表示(例如 Group1),在过滤器中,您将能够从包含枚举的所有文本表示的下拉列表中选择一个值。

If you can't (or don't want to) change the Property of your InvoiceModel you can still make use of the ClientGroupEnum by using the following GridColumn:如果您不能(或不想)更改 InvoiceModel 的属性,您仍然可以通过使用以下 GridColumn 来使用 ClientGroupEnum:

<GridColumn Field="@(nameof(InvoiceModel.ClientGroupId))" FieldType="@(typeof(ClientGroupEnum))" Title="ClientGroup" Width="300px" Filterable="true"/>

With the FieldType Parameter you are telling the Grid that the int values shall be treated as Enum values.使用 FieldType 参数告诉网格 int 值应被视为枚举值。

If your ClientGroup table does change at runtime you could use a ClientGroupName Property instead of ClientGroupId Property in your InvoiceModel.如果您的 ClientGroup 表在运行时发生变化,您可以在 InvoiceModel 中使用 ClientGroupName 属性而不是 ClientGroupId 属性。 This means that you can't use the same Invoice Class that represents your Invoice Database Table but you have to use an InvoiceViewModel Class instead and fill it with the appropriate data at runtime.这意味着您不能使用表示您的发票数据库表的同一个发票类,而必须使用 InvoiceViewModel 类,并在运行时用适当的数据填充它。 With an InvoiceViewModel class with an ClientGroupName Property you could use the following Column:使用具有 ClientGroupName 属性的 InvoiceViewModel 类,您可以使用以下列:

<GridColumn Field="@(nameof(InvoiceViewModel.ClientGroupName))" Title="ClientGroup" Width="300px" Filterable="true"/>

You can then use the build in filters such as "contains" or "startsWith" but you won't have a dropdown with valid values.然后,您可以使用内置过滤器,例如“contains”或“startsWith”,但不会有包含有效值的下拉列表。

If you don't want to create a separate ViewModel class or you really need a dropdown, you will have to use Filter Templates as described here .如果您不想创建单独的 ViewModel 类,或者您确实需要一个下拉列表,则必须使用此处所述的过滤器模板。 In the Filter Template you could place a dropdown filled with the values of your ClientGroup table.在过滤器模板中,您可以放置​​一个下拉列表,其中包含您的 ClientGroup 表的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM