How to set the (display)template of a column in a datatable

Hi everyone,

I've been playing with creating my own displaytemplate for rendering fields.
This is straightforward

        fd.field(fieldName).widgetOptions = {
            template: template
        }
    }

Now I want to stretch this a little but further, and set the displaytemplate of a specific column in a datatable.
In the GUI, this dan be done like

But can this template also be set by javascript?

What I already tried...

if

myControl = "SPDataTable1"
dt = fd.control(myControl)

then

dt._columns

contains

'[{"@Name":"Dossier","@Type":"String","@InternalName":"Dossier","@Mode":"Custom","@CustomTemplate":"\\"return \\\\u0027\\\\u003ca href=\\\\u0022\\\\u0027 + \\\\u0027./EditForm.aspx?item=\\\\u0027 + ctx.row.ID + \\\\u0027\\\\u0022\\\\u003e\\\\u0027 + ctx.row.Dossier + \\\\u0027\\\\u003c/a\\\\u003e\\\\u0027\\""}]'

So it seams that my custom displaytemplate can be found in "@CustomTemplate"

Is this the place were I should programatically put my own display logic? Is this supported?

Or is there an easier way? Something like

dt.widget.columns

contains my column,
but I can't my defined displayed tempate in for example

dt.widget.columns[2].widgetOptions 

any suggestions?
kind regards,
bartplessers

Aaaarghhhhh.
all credits to my collegue @asmita_adh

solution:

dt.templates = {
    myColumnName: function (ctx) {
        return '<a href="' + './EditForm.aspx?item=' + ctx.row.ID + '">' + ctx.row.Dossier + '</a>'
    }

cheers!

1 Like