I want to set a user-defined search value in a filter on a kendo grid. As soon as the user opens the filter, the value will be placed into the search box. Any advice would be much appreciated.
This is similar question to Set default filter for Kendo UI Grid except that I'm using angular js and I want a user-defined string filter value:
This is how I build my grid. I'm using angular js to create a div with custom attributes. The most notable attributes are sg-grid
(the kendo grid itself), sg-filterable
(set to true to indicate that this grid should be filterable) and sg-predefine-filter
(also set to true to indicate that this grid's filter should have a string entered into the search box when it opens):
Markup
<div sg-grid sg-data="api/grid/accounts" sg-columns="accountId,name,pricingFrequency,shortName,status" sg-filterable="true" sg-predefine-filter-value="true" </div>
Scripting (simplified to demo here)
angular.module('sgComponents').directive('sgGrid', [ return { restrict: 'AE', scope: { filterable: @sgFilterable, predefineFilterValue: @sgPredefineFilterValue}, template: '<div class="sg-grid">\ <div class="pager-bar">\ <div></div>\ // THE KENDO GRID </div>\ </div>', link: function(scope, element, attrs) { buildGrid(); function buildGrid() { var grid = element.find(':nth-child(2)'); // 2nd DIV IN THE TEMPLATE var gridOptions = buildGridOptions(scope, attrs, grid); grid.kendoGrid(gridOptions); // build the grid }; /** Builds the options for the grid */ function buildGridOptions(scope, attrs, grid) { if (scope.filterable === 'true') { opts.filterable = {}; opts.filterable.operators = {}; opts.filterable.operators.string = {} if (scope.predefineFilterValue === 'true') { // set a pre-defined value if true opts.filterable.operators.string = { eq: 'Is equal to', value:'Test' } } else { // just show the filter option opts.filterable.operators.string = { eq: 'Is equal to' } } } } } }; ]);
Here is an image of the console log:
The outcome. As you can see, my value is added as another filter option. I don't want this, I want it to be in the input box as a value!