Evaluating Function in String Format on Grid Click Handler

3 posts, 0 answers
  1. Ryan
    Ryan avatar
    17 posts
    Member since:
    Oct 2016

    Posted 03 Nov 2016 Link to this post

    Hello, I have a Kendo Grid I am creating from JSON data.  I am attempting to pass a function to a custom Command button's click event within the grid to get that row's data when it is clicked.  Due to my grid data coming from JSON, my command field's click event in my column array is stored as a string value. 

    In JSON, my command field looks as follows:

                                          "command": [
                                              "name": "Select",
                                              "click": "testFunction();"

    When the button is clicked in the grid, I am given the following Console error:

    jquery-2.1.4.min.js:3 Uncaught TypeError: ((n.event.special[g.origType] || (intermediate value)).handle || g.handler).apply is not a function(…)

    I have attempted to pass in testFunction as "eval(testFunction() );" and even attempted to recreate my column data with a New Function object instead of the string, however I could not get the column array to play nice with Kendo and consistently received e.chartAt errors when the grid attempted to parse.  I used the following demo to create my column data dynamically:


    I really would like to simply specify my function call from the JSON data.  I have also thought about finding the Click event from within Kendo UI and attempting to parse my string there as well.  I can't think of any other ways to get this to function from JSON data.

  2. Rosen
    Rosen avatar
    3253 posts

    Posted 07 Nov 2016 Link to this post

    Hello Ryan,

    As I have mentioned in the other ticket you have open to this matter strings are not valid values for the click options of the column.command as it is only supports function reference. Therefore, you should make sure a valid function is provided.

    Using eval over the string in question will not work as the string contains a function call, instead of a function reference. You may trying modifying the JSON string to have only the function name instead, for example:

      "click": eval("testFunction")

    Telerik by Progress
    Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
  3. Ryan
    Ryan avatar
    17 posts
    Member since:
    Oct 2016

    Posted 07 Nov 2016 Link to this post

    I got around my issue by creating a function object using the function constructor.  Better formatting can be found on my Stackoverflow posting where I answer my own question.


Back to Top