Grid search doesn't work when operator explicitly specified

1 Answer 160 Views
Grid
kva
Top achievements
Rank 2
Iron
Iron
Iron
kva asked on 19 Jul 2023, 08:21 AM | edited on 21 Jul 2023, 05:33 AM

This is my grid:

@(Html.Kendo().Grid<Project>()
    .Name("ProjectsGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ProjectName)
            .ClientTemplate("<a href=/Directory/project/${Id} target=_blank>${ProjectName}</a>")
            .Width(180);
        columns.Bound(p => p.ProjectManager).Width(230)
            .ClientTemplate("#=data.ProjectManager?.Name#")
            .EditorTemplateName("WorkingEmployee")
            .Sortable(s => s.Compare("(a, b) => compareManager(a, b)"));
        columns.Bound(p => p.IsActive)
            .Width(180)
            .ClientTemplate("#: IsActive ? 'Yes' : 'No' #");
    })
    .ToolBar(toolbar =>
    {
        toolbar.Save();
        toolbar.Search();
    })
    .Search(s =>
    {
        s.Field(e => e.IsActive);
        s.Field(e => e.ProjectName, "contains");
    })
    .Sortable()
    .Editable(GridEditMode.InCell)
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Field(p => p.ProjectManager).DefaultValue(
                ViewData["defaultProjectManager"] as User);
            model.Field(p => p.ProjectName).Editable(false);
        })
        .Read("Projects_Read", "Directory")
        .Update("Projects_Update", "Directory")
    ))

 

With "s.Field(e => e.ProjectName, "contains");" it throws:

 

Uncaught TypeError: e.charAt is not a function kendo.all.js:2114

 

Without this, it runs correctly.

 

Additional question

Also, I would like to know how to search for value of bool variable. The variable is shown as yes, no words. When I search for no, it should show me records where value is false. How to implement this?

Stoyan
Telerik team
commented on 21 Jul 2023, 07:06 PM

Hello Kva,

This issue usually occurs when there is mismatch between the field's type and the supported operators for that specific type. The "contains" filter operator is only supported by fields of type string.

Additionally, it seems that the ProjectName might contain some special symbols that could also cause the reported issue.

If the issue persists, even after the ProjectName type is set to string please consider sharing an example of the ProjectName field's values. This will enable me to try to replicate the reported issue on my side.

In regard to your second question - applying custom filters for boolean fields is currently not supported by the Grid's search. However, I will research whether any workaround is available and will let you know of my findings.

Regards,
Stoyan
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

1 Answer, 1 is accepted

Sort by
1
Accepted
Stoyan
Telerik team
answered on 25 Jul 2023, 04:07 PM

Hello Kva,

I have devised a way to modify the Using Search Box to Filter the Grid Data by Date Knowledge Base article to parse the boolean field at the Grid's Model.

        .Schema(schema =>
        {
            schema.Model(model =>
            {
                model.Id(x => x.ProductID);
                model.Field(p => p.Discontinued).Parse("parseBool");
            });
        })

This way it checks whether any fields contain the "Yes" or "No" strings and parses them either to true or to false.

    function parseBool(val){
        var s = val.toString();
        if (s.indexOf("Yes") !== -1 || s.indexOf("yes") !== -1 || val==true){
            return true;
        } else if(s.indexOf("No") !== -1 || s.indexOf("no") !== -1 || val==false ) {
            return false;
        }
    }

Please be aware that the Schema.Model.Parse configuration property of the DataSource is only available when the DataSource Type is set to Custom.

For your convenience I have applied the snippets above to this Telerik REPL example. Give the suggestion a try and let me know how it works on your side.

Regards,
Stoyan
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Grid
Asked by
kva
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Stoyan
Telerik team
Share this question
or