Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI GRID - Custom Cell Templates Code Separation

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.

like image 307
Rishi Katyal Avatar asked Apr 01 '26 04:04

Rishi Katyal


2 Answers

You 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>
like image 51
Villanuevand Avatar answered Apr 02 '26 17:04

Villanuevand


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' }  
];
like image 38
Vikash B Avatar answered Apr 02 '26 18:04

Vikash B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!