This is a migrated thread and some comments may be shown as answers.

How to filter Multi Checklist item against column with html tag

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Iron
Veteran
Jimmy asked on 09 Dec 2020, 12:10 PM

I have a column with html code. i.e. <div style='color: green'> Active</div>

and I have the filterable operator set to "Contains" but the filter result is alway not found.

 

@(Html.Kendo().Grid(Model.Transaction)
.Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.DisplayLeaseStatus).Title("Transaction Status").HtmlAttributes(new { style = "text-align:center" }).Filterable(ftb => ftb.Multi(true).BindTo(new[]{
                                    new { DisplayLeaseStatus = Active },
                                    new { DisplayLeaseStatus = Expired },
                                    new { DisplayLeaseStatus = Terminated }
                                    };));
 
})
 
.Scrollable(scrollable => scrollable.Height("auto"))
.Filterable(filterable => filterable
    .Extra(false)
    .Operators(operators => operators
        .ForString(str => str.Clear()
            .Contains("Contains")
        )
)
.Events(e => e.DataBound("dataBoundHandler"))
.DataSource(dataSource => dataSource
    .Ajax()
    .ServerOperation(false)
    .PageSize(50)
    .Events(e => e.Error("onError").RequestEnd("onRequestEnd")))
    .Resizable(resize => resize.Columns(true))
    .Reorderable(reorder => reorder.Columns(true))
    )

 

and the column data contents i.e. <div style='color : greed'> Active </div>

</div>

 

Any advice how i can filter this?


1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 14 Dec 2020, 08:27 AM

Hi Jimmy,

When the MultiCheckbox filter of the grid is set up, the filter expressions are always built with the "eq" (equals) operator. Therefore, setting the Contains operator via the options will not affect the MultiCheckbox.

What I can recommend is that you actually store only the values in the database rather than the whole HTML value. This way, you would further decrease the chance of submitting arbitrary values that might do harm to the database. After that handle the styling with a ClientTemplate.

Any other approach would require custom logic that might be error-prone. Do let me know if the suggestion above is not applicable in your scenario. 

 

Best regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Answers by
Tsvetomir
Telerik team
Share this question
or