Skip to content Skip to sidebar Skip to footer

Is It Possible Have This Code Equivalent Code In Kendo External Template

I have this dojo with its inline template var actionName = 'read'; $('#grid').kendoGrid({ columns: [ { field: 'name' }, { field: 'age' } ],

Solution 1:

The parametr (which you named) dataItem takes over data from current row. Then you need to write property which you want to render. dataItem is valid for whole template.

<script id="detailTemplate"type="text/x-kendo-template">
    #: read #
</script>

and

detailTemplate: function(dataItem){ 
    return kendo.template($("#detailTemplate").html())(dataItem);
}

should be enough.

Dojo example

Parameter of function in detailTemplate will contains all properties from object in row (even not visible as column). So if you will do some special calculations or something you can do it in detailtemplate function and create new property which will be accesible by name in template.

Dojo example 2

Edit: If you want run (let's say) some command, which is in string you have to use eval function. This function will execute the text. It means if you will use some functuion name as eval parameter, this function will be executed.

Dojo example 3

Yet, I dare to quote one important paragrapg from this site: eval - mozila developer

Don't use eval needlessly!

eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension. More importantly, third party code can see the scope in which eval() was invoked, which can lead to possible attacks in ways to which the similar Function is not susceptible.

eval() is also generally slower than the alternatives, since it has to invoke the JS interpreter, while many other constructs are optimized by modern JS engines.

There are safer (and faster!) alternatives to eval() for common use-cases.

Post a Comment for "Is It Possible Have This Code Equivalent Code In Kendo External Template"