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

Overriding grid search panel function

1 Answer 607 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Iron
Iron
Boris asked on 12 May 2020, 09:53 AM

Hello guys,

I'm interested if it's possible to override the current search panel function, mostly for two reasons:

  1. to call the function on click, not keyup event
  2. to prevent existing filters from being deleted?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 14 May 2020, 09:26 PM

Hi, Boris,


The search panel functionality is executed within the input event of the textbox. Every time a character is added or deleted, a filter expression is built and applied to the data source. The default application of the filter cannot be alternated. 

As an alternative, I would recommend creating a custom textbox and executing the filter expression after a button has been clicked:

  .ToolBar(tb=>tb.ClientTemplateId("template"))

 

And the template needed for the input and button:

<script id="template" type="text/x-kendo-template">
    <div>
        <span><input type="text" id="search" class="k-textbox"></span>
        <span>
            @(Html.Kendo().Button()
                        .Name("textButton")
                        .HtmlAttributes(new { type = "button" })
                        .Content("Search")
                        .Events(ev => ev.Click("filterGrid")).ToClientTemplate())
        </span>
    </div>

 

Within the click event handler, build a filter expression that adds the previously selected filters and apply it to the data source: 
 function filterGrid() {
        var searchFileld = $("#search");
        var searchValue= searchFileld.val();
        var grid = $('#grid').data('kendoGrid');
        var preselectedFilters = new Array;

        $(grid.dataSource.filter().filters).each(function () {
            preselectedFilters.push(this);
        });

        preselectedFilters.push({
            logic: "or",
            filters: [{
                field: "ShipName",
                operator: "contains",
                value: searchValue
            },
            {
                field: "ShipCity",
                operator: "contains",
                value: searchValue
            }]
        });
        grid.dataSource.filter(preselectedFilters);
    }

Let me know if further assistance is needed.

Regards,
Anton Mironov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Iron
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or