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

Create unique name for grid in template

1 Answer 937 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Ludek Soukup
Top achievements
Rank 1
Ludek Soukup asked on 18 Aug 2016, 12:46 PM

Hi,
I need to create unique grid name inside template, i try with javascript, but it doesn't work.

<script id="conditionGroupTemplate" type="text/x-kendo-template">
    @(Html.Kendo().Grid<Rule.ConditionViewModel>()
                  .Name("entryGroupConditions" + //here i need to call getGUID()//)
                  .Columns(columns =>
                  {
                      columns.Bound(o => o.Text);
                      columns.Command(command =>
                      {
                          command.Destroy();
                      }).Width(110);
                  })
                  .ToolBar(toolbar =>
                  {
                      toolbar.Template("<div class='toolbar'><a class='k-button k-button-icontext pull-left' onClick='AddGroup(\"\\#entryGroupConditions\", \"Skupina podmínek\")'><span class='k-icon k-add'></span>Přidat skupinu</a><h3>AND</h3></div>");
                  })
                  .ClientDetailTemplateId("conditionTemplate")
                  .AutoBind(false)
                  .DataSource(ds => ds
                      .Ajax()
                      .Model(m => m.Id(o => o.Path))
                      .Destroy(del => del.Action("DeleteAttribute", "Rule"))
                  )
                  .Resizable(resize => resize.Columns(true))
                  .ToClientTemplate()
    )
</script>

function getGUID(){       
        return (salt() + salt() + "-" + salt() + "-4" + salt().substr(0,3) + "-" + salt() + "-" + salt() + salt() + salt()).toLowerCase();
    }
 
    function salt(){
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }

Any help?
thanks

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 22 Aug 2016, 12:30 PM
Hi Ludek,

The Name string of the Grid can contain a Kendo UI template expression, for example:

http://demos.telerik.com/aspnet-mvc/grid/hierarchy

.Name("grid_#=EmployeeID#")

... where EmployeeID is the unique primary key field in the master Grid.

One may expect to be able to use something like this:

.Name("entryGroupConditions#=getGUID()#")

http://docs.telerik.com/kendo-ui/framework/templates/overview#handle-external-templates-and-expressions

However, this approach cannot be used for widget names, due to special escaping that occurs behind the scenes.

That's why the expression inside the Grid Name() can only contain a variable reference, and no function calls or arithmetic operators. The variable can be either a custom global variable from the page, or a field from the master Grid's data item.

Regards,
Dimo
Telerik by Progress
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Tags
Templates
Asked by
Ludek Soukup
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or