strings as parameter inside a template

5 posts, 0 answers
  1. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 25 Apr 2013 Link to this post

    Hello again,
    if i want to pass inside a javascript function,a string parameter how can i do that?

    for example this sentence
    .ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext k-grid-add' onclick='addCustomCheckBoxField('IsHour')' href='javascript: void(0)'><span class='k-icon k-add'></span>add</a>"))

    gives me an syntax error.
    i would like to pass the IsHour as a string value for the function.
    Maybe it is more a javascript problem,but it is used in kendo ui context.

    Regards,
    Daniel
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2284 posts

    Posted 25 Apr 2013 Link to this post

    Hi Daniel,


    In the current scenario you should escape the quotes of the paratemer.
    E.g.
    .ToolBar(toolBar => toolBar.Template("<a class='k-button k-button-icontext k-grid-add' onclick='addCustomCheckBoxField(\"IsHour\")' href='javascript: void(0)'><span class='k-icon k-add'></span>add</a>"))

    I hope this information was helpful for you. Please let me know if I could assist you further.

     

    Regards,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 25 Apr 2013 Link to this post

    it's ok,from syntax point of view,but a strange thing happens:
    if i leave for example inline template for a column like this:
    @(Html.Kendo().Grid<UCMSPayroll.ViewModels.TallyMeasurementViewModel>()
    .Name("Grid")

    .Columns(columns =>
    {
    columns.Bound(p => p.IsActive).ClientTemplate("<input type='checkbox' disabled='true' name='IsActive' #= IsActive ? checked='checked' : '' # />").Title(UCMSPayroll.Resources.Resources.FieldText_TM_IsActive);
    ...
    }
    it's ok,but if i replace that template with the javascript function like this

    columns.Bound(p => p.IsActive).ClientTemplate("#= addCustomCheckBoxIsActive() #").Title(UCMSPayroll.Resources.Resources.FieldText_TM_IsActive);

    even without parameters,it doesn't evaluate the field ,in this case IsActive,like there is no more bounded to that column,and in may case some of them should be false so it would be unchecked ,here all are checked.

    Is there a diference?why is happening this problem?

    Regards,
    Daniel
  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2284 posts

    Posted 26 Apr 2013 Link to this post

    Hi Daniel,


    I am not sure that I understand the second scenario from your post. With this setup the content of the cell will be the result of the evaluated JavaScript function. Here a sample, which demonstrates this.

    E.g.
    .Columns(columns =>
    {
        ...
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.UnitPrice);
        columns.Bound(p => p.UnitsInStock).ClientTemplate("#= myFunc(ProductName, UnitPrice)#");
    })

    function myFunc(ProductName, UnitPrice) {
        return "Info: " + ProductName + " " + UnitPrice;
    }

    I hope this information was helpful for you.

     

    All the best,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 29 Apr 2013 Link to this post

    Well in my example i was missing as parameter the field, and now i tried the following

    columns.Bound(p => p.IsActive).ClientTemplate("#= addCustomCheckBoxIsActive(IsActive)#").Title(Namespace.Resources.Resources.FieldText_TM_IsActive);

    and in my javascript function

    function addCustomCheckBoxIsActive(IsActive) {
    return "<input type='checkbox' disabled='true' name='"+IsActive+"' #= "+IsActive+" ? checked='checked' : '' # />";
    }
    also tried
    function addCustomCheckBoxIsActive(IsActive) {
    return "<input type='checkbox' disabled='true' name='"+IsActive+"' #= IsActive ? checked='checked' : '' # />";
    }
    And is not working and i think because he doesn't know anymore who is IsActive,is out of the context,so i  need  the function to evaluate the value of IsActive as a boolean database field,and based on that return a checked or unchecked checkbox.

    So in order to return the html code based on its value i did something like this
    function addCustomCheckBoxIsActive(IsActive) {
       if (IsActive)
          return "<input type='checkbox' disabled='true' name='IsActive' checked='checked' />";
       else
          return "<input type='checkbox' disabled='true' name='IsActive' />";
    }
    otherwise he doesn't know how to evaluate that inside template;

    Regards and thanks,
    Daniel
Back to Top