EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: gordis gmbh on June 20, 2016, 07:57:05 AM



Title: datagrid filter textboxes - set prompt
Post by: gordis gmbh on June 20, 2016, 07:57:05 AM
How can I set a default prompt to all the filter textboxes of all filter-enabled datagrids?

The prompt may be for e.g. 'enter filter text here...'



Title: Re: datagrid filter textboxes - set prompt
Post by: stworthy on June 20, 2016, 06:13:49 PM
Just set the 'prompt' option for the textbox.

Code:
dg.datagrid('enableFilter', [{
    field:'attr1',
    type:'textbox',
    options:{
        prompt:'enter filter text here...'
    }
}]);


Title: Re: datagrid filter textboxes - set prompt
Post by: gordis gmbh on June 23, 2016, 02:33:01 AM
To enable filter as per your suggesstion one needs field name.

We enable filter for all datagrids in one central location as follows:
Code:
	if (specialFilters.length > 0) {
$('#'+datagridSelector).datagrid('enableFilter', specialFilters); // enable filter with given special filters
} else {
$('#'+datagridSelector).datagrid('enableFilter'); // enable filter with type textbox
}

As you can see, there is no datagrid-field information given for textbox-based filters. Special filters are combobox or datebox or numberbox filters which contain field-name and corresponding options...

For time being I found a workaround by adding the following line directly in source code file "datagrid-filter.js":
Code:
input.attr('placeHolder', 'enter filter text here ...');

This works but I am looking for a possibility to do the same - by default - for all filter-enabled datagrids without modifying the source code.

Perhaps by extending the filter - plugin in my code. But the problem is, setting the prompt after the textbox is initialised effects the textbox size! Any ideas in this direction are welcome ...



Title: Re: datagrid filter textboxes - set prompt
Post by: stworthy on June 23, 2016, 07:58:56 AM
You can override the 'defaultFilterType' and 'defaultFilterOptions' to set properties for all un-specialed fields.
Code:
var dg = $('#dg').datagrid({
    defaultFilterType: 'textbox',
    defaultFilterOptions: $.extend({},$.fn.datagrid.defaults.defaultFilterOptions,{
        prompt:'enter filter text here...'
    })
});