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

Angular gridOptions change filter operator order in a multilanguage app

4 Answers 241 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Enrico
Top achievements
Rank 1
Enrico asked on 23 Sep 2015, 07:26 PM

Hi,

I want to change the default operators order for string fields, to do so I know I could redefine them this way:

 this.gridOptions = {
                filterable: {
                    mode: 'row',
                    operators: {
                        string: {
                            contains: 'Contains',
                            doesnotcontain: 'Does not contain',
                            startswith: 'Starts with',
                            endswith: 'Ends with',
                            eq: 'Is equal to',
                            neq: 'Is not equal to'
                        }
                    }
                }
            };

Doing so, since the application is multi-language, I'm losing the default translations provided by the loaded culture files.

Do you have an idea to simple solve that?

Thanks,

Enrico

4 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 28 Sep 2015, 08:32 AM
Hello Enrico,

In general, the messages are defined through this operators.string option. If it is overriden, then the default messages will be lost and the new ones will be used. That being said, you will need to define the correct localized messages manually. You can try to extract them from the grid  and build the correct string operators from them instead of defining a static ones with en-US messages.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Enrico
Top achievements
Rank 1
answered on 29 Sep 2015, 04:13 PM

Hi,

is there any angular event emitted by kendo in kendo.culture() method?

If yes I could do semething like that:

$rootScope.$on('$kendoEventCultureChanged', (event, data) => {

                var messages: any = kendo.ui;
                this.gridOptions.filterable.operators.string = messages.FilterCell.prototype.options.operators.string;
            });

if not I could still do that by emitting an application event after setting the new language.

BR,

Enrico

0
Enrico
Top achievements
Rank 1
answered on 29 Sep 2015, 08:23 PM

Hi,

this is the final solution I've ended up and it works pretty well:

First: define the operators order in the datasource

this.gridOptions = {
                filterable: {
                    operators: {
                        string: { // define operators order
                            contains: '',
                            doesnotcontain: '',
                            startswith: '',
                            endswith: '',
                            eq: '',
                            neq: ''
                        }
                    }
                }
            };​

Second: rise an event after the kendo culture has been set

kendo.culture(language);
$rootScope.$broadcast('myApp:kendoCultureChanged');​

Third: apply the operator string object that will contain the right translations

$rootScope.$on('myApp:kendoCultureChanged', (event, data) => {
                // operators string localization after kendo culture changed
                var stringOperators = (<any>kendo.ui).FilterCell.prototype.options.operators.string;
                this.gridOptions.filterable.operators.string.contains = stringOperators.contains;
                this.gridOptions.filterable.operators.string.doesnotcontain = stringOperators.doesnotcontain;
                this.gridOptions.filterable.operators.string.startswith = stringOperators.startswith;
                this.gridOptions.filterable.operators.string.endswith = stringOperators.endswith;
                this.gridOptions.filterable.operators.string.eq = stringOperators.eq;
                this.gridOptions.filterable.operators.string.neq = stringOperators.neq;
            });​

BR,

Enrico

0
Bridge24
Top achievements
Rank 1
Iron
answered on 08 Mar 2016, 05:21 AM

Hi Enrico, thank  you for that solution for multi-language, that will make me save lot of time! 

But I totally agree, the "operators: string: {...}" property of the kendo grid, we should be able to add "operators" in different order, WITHOUT the need to specify a new text for each.  We should be able to fill an array of operators, like: 

operators: {string: ["contains", "eq", "neq", ...]}

That is something the telerik team should do I think.  

I found on the forum that lot of people need to set "contains" instead of "equal" as the default value, and they use the operators: string object to achieve that.  But that request has nothing to do with the "text" of the operator.

Thank you

Tags
Grid
Asked by
Enrico
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Enrico
Top achievements
Rank 1
Bridge24
Top achievements
Rank 1
Iron
Share this question
or