how to use EditorTemplateName?

2 Answers 5011 Views
Grid
xu
Top achievements
Rank 1
xu asked on 28 Jun 2012, 04:24 AM

it's not work,how to use EditorTemplateName?

columns.Bound(u => u.RoleNameString).EditorTemplateName(
"roles_editor"

);



<script type="text/javascript">

function roles_editor()

 

{

}

</script>

 

 

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 29 Jun 2012, 05:03 AM
EditorTemplateName points to an MVC EditorTemplate, not Javascript. If you want to use JS, you need to use a ClientTemplate for that.

If you look at C:\Program Files (x86)\Telerik\Kendo UI for ASP.NET MVC Q2 2012 BETA\Examples\Views\Shared\EditorTemplates, you will see some example EditorTemplates that will override the default ASP.NET MVC templates with Kendo behaviors. You can add your own Template for a given model in that folder, and then EditorTemplateName would be the name of the file you want to use. In the case of the examples, you would use .EditorTemplateName("Time") or .EditorTemplateName("Currency").

Let me know if that is not clear and I can see if I can point to a better example.
Stefan
Telerik team
commented on 23 Oct 2017, 08:30 AM

Hello,

I want to clarify that the description provided by Robert is correct.

The ClientTemplate can be a function and it is executed on the client to show the data in preview(non-edit) mode:

https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-customize-the-way-properties-are-displayed-in-grid-bound-columns

The EditorTemplate is pointing to a template(View) which is placed inside the Views\Shared\EditorTemplates folder. This template is used to initialize an editor which will be shown when the column is edited:

https://docs.telerik.com/aspnet-mvc/helpers/grid/templating/editor-templates#editor-templates

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Stephanie
Top achievements
Rank 1
commented on 08 Feb 2018, 05:38 PM

How can you direct the EditorTemplateName to a folder in an AREA? Right now it only searches the Project Shared/EditorTemplates/name.cshtml folder. It doesn't work when the template is placed in Area/Shared/EditorTemplates/name.cshtml

 

Konstantin Dikov
Telerik team
commented on 13 Feb 2018, 02:06 PM

Hello Stephanie,

Currently the editor templates could be placed only in the Views folder. You could follow the item below, which covers the Area scenario as well:

Best Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Samarth
Top achievements
Rank 1
commented on 15 Jul 2020, 08:43 AM

how can i define .EditorTemplateName("mytemplate") in tag helper kendo grid column for .net core
Anton Mironov
Telerik team
commented on 17 Jul 2020, 02:01 PM

Hello, Samarth,

In order to use an editor template with the TagHelper implementation of the Kendo UI Grid, use a JavaScript function for initializing the editor. It will not be taken from the EditorTemplates folder. This is due to the fact that the mechanics of the TagHelpers are different compared to the HtmlHelpers.

Here is an example:

<column field="SupportRep" title="Support Rep" editor="supportRepDropDownEditor"></column>
Where the supportRepDropDownEditor is a JavaScript function that initializes a DropDownList widget:
function supportRepDropDownEditor (container, options) {
                    $('<input required name="' + options.field + '"/>')
                        .appendTo(container)
                        .kendoDropDownList({
                            autoBind: false,
                            dataTextField: "CategoryName",
                            dataValueField: "CategoryID",
                            dataSource: {
                                type: "odata",
                                transport: {
                                    read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
                                }
                            }
                        });
                }
I hope this information helps.

 

Kind Regards,
Anton Mironov
Progress Telerik

0
Chris
Top achievements
Rank 1
answered on 30 May 2017, 07:42 AM

This information is wrong or outdated. You can use EditorTemplateName to point to a function like so:

columns.Bound(o => o.MyColumn).EditorTemplateName("myTemplate");

 

function myTemplate(container, options) {
    // create an input element
    var input = $("<input/>");
    // set its name to the field to which the column is bound ('name' in this case)
    input.attr("name", options.field);
    // append it to the container
    input.appendTo(container);
    // initialize a Kendo UI AutoComplete
    input.kendoAutoComplete({
        dataTextField: "name",
        dataSource: [
            { name: "Jane Doe" },
            { name: "John Doe" }
        ]
    });
}
Alexandra
Top achievements
Rank 1
commented on 18 Oct 2017, 01:47 PM

Hi Telerik Team,

Has the functionality Chris mentioned worked in the past? How can I achieve that functionality now in MVC? Is my only solution in order to have that functionality to write javascript code?

Alexandra
Top achievements
Rank 1
commented on 18 Oct 2017, 01:49 PM

Sorry Chris but Robert is right. Robert's description is the actual functionality.
Chris
Top achievements
Rank 1
commented on 18 Oct 2017, 02:57 PM

Yes I think you're right; not sure where I got that from at the time.
Tags
Grid
Asked by
xu
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or