field default value from anonymous function

5 posts, 0 answers
  1. Cagatay
    Cagatay avatar
    15 posts
    Member since:
    Dec 2011

    Posted 26 Feb 2012 Link to this post


    I've tried

                schema: {
                    type: "json",
                    model: {
                        id: "id",
                        fields: {
                            c_pmchart: {type: "string", validation: { required: true }},
                            defi: { type: "string", validation: { required: false }, defaultValue: function () {return 'test value';} },

    to set a field's defaultValue via an anonymous function but it di not work. Any ideas how to set deafultValues by a function  ?

  2. Nikolay Rusev
    Nikolay Rusev avatar
    2277 posts

    Posted 27 Feb 2012 Link to this post

    Hello Cagatay,

    I am afraid that defaultValue should be value, not a function. It is not supported to have the default field value as a function.

    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Robert
    Robert avatar
    38 posts
    Member since:
    Feb 2012

    Posted 16 Jun 2014 in reply to Cagatay Link to this post

    A Telerik employee posted this solution elsewhere:

    The gist is here, where the code sets one of the values equal to the currently-specified filter in that grid column:
    defaultValue: function(e) {
      if(typeof this.CategoryID === "function") {
        var grid = $("#grid").data("kendoGrid");
        var ds = grid.dataSource;
        var filter = ds.filter();
        if(filter && filter.filters[0].field === "CategoryID") {
            this.set("CategoryID", filter.filters[0].value);
        } else {
            this.CategoryID = 1;

    Hope this helps!
  4. Tim
    Tim avatar
    2 posts
    Member since:
    Jul 2015

    Posted 08 Aug in reply to Robert Link to this post

    Are you defining the datasource in the scope of the grid options or linking it?

    I ask because when I try this, e is undefined.  I'm working with a dataSource that's defined outside of the grid.
  5. Nikolay Rusev
    Nikolay Rusev avatar
    2277 posts

    Posted 11 Aug Link to this post

    Hello Tim,

    It doesn't matter how DataSource is defined the defaultValue function is called without arguments, thus e in this context will always be undefined. As you see in the code snippet it is not used anywhere in the function body.

    Nikolay Rusev
    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Back to Top