简体   繁体   English

来自远程模板的kendo ui网格可编辑弹出窗口

[英]kendo ui grid editable popup from remote templates

i'm trying to load html template for grid editable popup inside angular app . 我正在尝试加载角度应用程序内的网格可编辑弹出窗口的html模板。

inside the html page i added this 在html页面内我添加了这个

<script>

    var templateLoader = (function($,host){
        //Loads external templates from path and injects in to page DOM
        return{
            loadExtTemplate: function(path){
                var tmplLoader = $.get(path)
                .success(function(result){
                    //Add templates to DOM
                    $("body").append(result);
                })
                .error(function(result){
                    alert("Error Loading Templates -- TODO: Better Error Handling");
                });

                tmplLoader.complete(function(){
                    $(host).trigger("TEMPLATE_LOADED", [path]);
                });
            }
        };
    })(jQuery, document);

    /*
    ** Load the template file
    */
    templateLoader.loadExtTemplate("tpl/Maintenance/policyProp.htm");


    /*
    ** Loading external templates with in this function.
    */


</script>

inside the grid: 在网格内:

            editable: {
                confirmation: true,
                mode: "popup",
                template: kendo.template($("#Policy_editor").html())
            },

the htm page: htm页面:

<script type="text/x-kendo-template" id="Policy_editor" >
html code here 
.
.
.
.
</script>

i want "#Policy_editor" to come from an external html page. 我希望“#Policy_editor”来自外部html页面。 thanks for your help! 谢谢你的帮助!

Personally, I would do some changes in your code. 就个人而言,我会对您的代码进行一些更改。 It's appending the content inside the body, which isn't what you want. 它将内容附加到正文中,这不是您想要的。 You need to append the content inside the javascript tag. 您需要在javascript标记内附加内容。 The snippet you're using is nothing more like a wrapper to the jQuery's $.get() method, but it doesn't let you decide what to do with the request result. 您正在使用的代码段不再是jQuery的$.get()方法的包装器,但它不允许您决定如何处理请求结果。 You need to change that in order to make it work: 您需要更改它才能使其工作:

  1. Add a callback to the request wrapper: 向请求包装器添加回调:

     loadExtTemplate: function(path, successCallback) { ^ this parameter here 

    Then 然后

     .success(function(result){ if (successCallback) { successCallback(result); } }) 
  2. Now with the callback set, you have to create your grid inside it: 现在使用回调集,您必须在其中创建网格:

      templateLoader.loadExtTemplate("tpl/Maintenance/policyProp.htm", function(templateHtml) { $("#grid").kendoGrid({ .... editable: { confirmation: true, mode: "popup", template: kendo.template(templateHtml) }, }); }); 

    Why this? 为什么这个? Because you can append the remote html to the javascript tag after the grid initialization. 因为您可以在网格初始化后将远程html附加到javascript标记。 As it is an async request, in the moment of the grid initialization the template tag will be empty, so the widget will set an empty template to your column. 由于它是异步请求,因此在网格初始化时模板标记将为空,因此窗口小部件将为您的列设置一个空模板。 You need to create the grid after the request is complete in order to take the html template contents. 您需要在请求完成后创建网格才能获取html模板内容。 As you're already creating the grid inside the callback, no need to set it's contents to the tag, just use the templateHtml itself, which should contains the template html. 由于您已经在回调中创建了网格,因此无需将其内容设置为标记,只需使用templateHtml本身,其中包含模板html。

    If you can't or don't want to create the grid in that callback, you can try to change it's options when the request is complete, as the widget will be created already. 如果您不能或不想在该回调中创建网格,则可以在请求完成时尝试更改其选项,因为窗口小部件已经创建。 You can use setOptions() but I don't recommend this last option, I don't have good experiencies trying to change options of a kendo widget after initialization. 您可以使用setOptions()但我不推荐这最后一个选项,我没有很好的经验,尝试在初始化后更改kendo小部件的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM