Pass 'this' in template

2 posts, 0 answers
  1. Zeke Palmolive
    Zeke Palmolive avatar
    19 posts
    Member since:
    Jul 2012

    Posted 12 Mar 2013 Link to this post

    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
  2. Zeke Palmolive
    Zeke Palmolive avatar
    19 posts
    Member since:
    Jul 2012

    Posted 12 Mar 2013 Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
Back to Top