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

Evaluating Function in String Format on Grid Click Handler

2 Answers 341 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 03 Nov 2016, 10:45 PM

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:

http://jsbin.com/iharik/6/edit?html,js,output

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 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 07 Nov 2016, 08:28 AM

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")

Regards,
Rosen
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.
 
0
Ryan
Top achievements
Rank 1
answered on 07 Nov 2016, 05:38 PM

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.

http://stackoverflow.com/questions/40470459/create-an-anonymous-function-object-from-a-constructor-and-store-it-in-another-o

Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or