This is a migrated thread and some comments may be shown as answers.

Pass 'this' in template

1 Answer 81 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Zeke Palmolive
Top achievements
Rank 1
Zeke Palmolive asked on 12 Mar 2013, 05:59 PM
Hello,

I'm trying to pass a reference of a template'd checkbox in a grid to a Javascript function:

columns: [
...
     { title: " ", field: "someBoolean", sortable: true, template: "#= DisplayCheckbox(IDx, IDy, someBoolean, this) #" },
...
]

DisplayCheckbox looks like this:

function DisplayCheckbox(IDx, IDy, someBoolean, theCheckbox) {
    return '<input type="checkbox" onclick="AFunction(' + IDx + ', ' + IDy + ', ' + theCheckbox + ')" ' + (someBoolean === true ? 'checked ' : '') + (isAuthorized === true ? '' : 'disabled') + ' />';
}
I'm passing a reference of the checkbox in order to update the underlying model on check-change event.  I'm already doing other work via an AJAX call.  The update of the underlying datasource is to simply allow for sorting to work until the next page refresh.

If I'm going about this bass-ackwards, can you point me in the right direction to go?  If I am on the right track, you probably caught that I can't pass 'this' using the '#= ... #' template render directive.  How would I do that?

Thanks

1 Answer, 1 is accepted

Sort by
0
Zeke Palmolive
Top achievements
Rank 1
answered on 12 Mar 2013, 06:21 PM
Of course, I try something that I can't imagine working right after I type this out and it works.

Apparently this is ok:

{ title: " ", field: "aBool", template: "#= DisplayCheckbox(id1, id2, aBool, 'this') #" },
That said, if I am doing things a little weird I'd like to know.
Tags
Templates
Asked by
Zeke Palmolive
Top achievements
Rank 1
Answers by
Zeke Palmolive
Top achievements
Rank 1
Share this question
or