admin管理员组文章数量:1336192
I am trying to customize the cells using cellTemplates in UI-GRID. For this, I am defining templates in .js file, like this :
var template1 = '<div class="div1">{{COL_FIELD}}</div>';
var template2 = '<div class="div2">{{COL_FIELD}}</div>';
var template3 = '<div class="div3">{{COL_FIELD}}</div>';
I want to separate the HTML codes from .js file. Is there a way to define these templates separately in some .html file and using them in .js file. ?
Please Help.
I am trying to customize the cells using cellTemplates in UI-GRID. For this, I am defining templates in .js file, like this :
var template1 = '<div class="div1">{{COL_FIELD}}</div>';
var template2 = '<div class="div2">{{COL_FIELD}}</div>';
var template3 = '<div class="div3">{{COL_FIELD}}</div>';
I want to separate the HTML codes from .js file. Is there a way to define these templates separately in some .html file and using them in .js file. ?
Please Help.
Share Improve this question asked Jul 8, 2015 at 18:25 Rishi KatyalRishi Katyal 1756 silver badges16 bronze badges2 Answers
Reset to default 6You can use cellTemplate
differents ways:
var columnDefs = [
{ field: 'name', cellTemplate: 'name-template.html' },
{ field: 'name', cellTemplate: 'myTemplateId' },
{ field: 'name', cellTemplate: $.get('url-to-your-template.html') }
];
Your template can contain:
<div class="ui-grid-cell-contents"><a href="mailto:{{ COL_FIELD }}">Send E-Mail</a></div>
You can achieve it by coding as mentioned below
<script type = "text/ng-template" id = "myTemplate.html">
<div class="ui-grid-cell-contents"><a href="mailto:{{ COL_FIELD }}">Send E-Mail</a></div>
</script>
and then in your column definition provide the id mentioned for script tag in cellTemplate
var columnDefs = [
{ field: 'name', cellTemplate: 'myTemplate.html' }
];
本文标签: javascriptUI GRIDCustom Cell Templates Code SeparationStack Overflow
版权声明:本文标题:javascript - UI GRID - Custom Cell Templates Code Separation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742375656a2463110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论