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

JQuery: Update search fields for a grid after initialization

3 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
syian
Top achievements
Rank 1
Veteran
syian asked on 19 Oct 2020, 03:24 PM

How can I change the list of fields which will be included in the search of the grid after initialization? During the initialization you only have to define the search.fields configuration option, but apart from that it seems that it is not possible to change the list after the grid has been initialized. 

On the select event of a kendoDropDownList, I was hoping of calling something like the following and with that limiting the search only in the selected column of the grid:

$("#dropdownlist").kendoDropDownList({
  ...
  select: function(e) {
    jq("grid_id").data("kendoGrid").search.fields( [ option1 ] );
  },
  ...
});

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 21 Oct 2020, 03:09 PM

Hello,

You can use the Grid's setOptions method, to set the search field, for example:

var grid =  $("#grid").data("kendoGrid");
        
grid.setOptions({
  search: {
    fields: ["Country"] 
  }
})

Here's a dojo example with the logic above executed in a button's click handler: https://dojo.telerik.com/aHisefIF/2

Regards,
Ivan Danchev
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/.

0
syian
Top achievements
Rank 1
Veteran
answered on 22 Oct 2020, 08:44 AM
Hey Ivan, 
thank you! I totally forgot about the setOptions method. I tried it out and from my understanding it seems that setOptions does not preserve the Grid Toolbar Template - referring back to the documentation it clearly states exactly that: As a result, the templates will be lost once the setOptions() method is invoked.. But also mentions that by adding a template configuration should do the trick, which I did but still no template after choosing an option of the dropdown. I found a workaround by detaching the toolbar before loading the Grid settings (see Stackoverflow) in case someone needs it.
var grid =  $("#grid").data("kendoGrid");
let gridToolbar = jq("#grid .k-grid-toolbar").detach();      
grid.setOptions({
  search: {
    fields: ["Country"]
  }
})
jq("#grid .k-grid-toolbar").replaceWith(gridToolbar);
0
Ivan Danchev
Telerik team
answered on 26 Oct 2020, 08:35 AM

Hi syian,

Thank you for sharing the workaround with the community.

Regards,
Ivan Danchev
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
syian
Top achievements
Rank 1
Veteran
Answers by
Ivan Danchev
Telerik team
syian
Top achievements
Rank 1
Veteran
Share this question
or