Example below is a golang struct
type Column struct {
Data string `json:"data"`
Title string `json:"title"`
Type string `json:"type"`
Class string `json:"class"`
Visible bool `json:"visible"`
Render template.JS `json:"render"`
}
func (c *Column) SetValue() {
// code below is flexible depend on condition but here i keep it simple.
c.Render = template.JS(`function(data, type, row) { if(type === 'display'){ return $.fn.dataTable.render.text().display(data);} return data;}`);
}
Here is Javascript in golang template
<script>
$(function () {
console.log({{.Columns}}, wantedobj);
});
</script>
Here is chrome developer tools.
- left list is format value from struct above.
- right list is format that I want.
on render is there any posible way to get javascript function instead of string? (please see render at right picture)
