Angular gridOptions change filter operator order in a multilanguage app

5 posts, 1 answers
  1. Enrico
    Enrico avatar
    54 posts
    Member since:
    Jun 2013

    Posted 23 Sep 2015 Link to this post

    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

  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3747 posts

    Posted 28 Sep 2015 Link to this post

    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!
     
  3. Enrico
    Enrico avatar
    54 posts
    Member since:
    Jun 2013

    Posted 29 Sep 2015 in reply to Georgi Krustev Link to this post

    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

  4. Enrico
    Enrico avatar
    54 posts
    Member since:
    Jun 2013

    Posted 29 Sep 2015 in reply to Enrico Link to this post

    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

  5. Bridge24
    Bridge24 avatar
    90 posts
    Member since:
    Jan 2009

    Posted 07 Mar 2016 in reply to Enrico Link to this post

    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

Back to Top