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

strings as parameter inside a template

4 Answers 902 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 25 Apr 2013, 08:46 AM
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

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 25 Apr 2013, 10:42 AM
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!
0
Daniel
Top achievements
Rank 1
answered on 25 Apr 2013, 03:30 PM
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
0
Dimiter Madjarov
Telerik team
answered on 26 Apr 2013, 01:13 PM
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!
0
Daniel
Top achievements
Rank 1
answered on 29 Apr 2013, 07:31 AM
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
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or