Hello.
I have some problem with Grid.
I have some grid with colums: Id, firstName, lastName and template YearOfBirth...
Here is my viewModels
and here is my KendoGrid initialization
Everything is fine, but I can't sort my last column with template myFunc
How I can fix this ?
I have some problem with Grid.
I have some grid with colums: Id, firstName, lastName and template YearOfBirth...
Here is my viewModels
Person = kendo.data.Model.define({
id:
""
,
firstName:
""
,
lastName:
""
,
age:
""
,
myFunc: function () {
return
2013 -
this
.age;
}
});
viewModel = kendo.observable({
personArr: [],
loadDataFromController: function () {
personArr =
new
kendo.data.ObservableArray([]);
var vm =
this
;
$.ajax({
dataType:
'json'
,
url:
'/Home/GetPersons'
,
success: function (json) {
vm.setData(json);
}
});
},
setData: function (json) {
for
(var i = 0; i < json.length; i++) {
var temp =
new
Person();
temp.id = json[i].Id;
temp.firstName = json[i].FirstName;
temp.lastName = json[i].LastName;
temp.age = json[i].Age;
this
.
get
(
"personArr"
).push(temp);
}
}
});
viewModel.loadDataFromController();
kendo.bind($(
'#PersonGrid'
), viewModel);
and here is my KendoGrid initialization
<div id=
"PersonGrid"
>
@(Html.Kendo().Grid(Model)
.Name(
"Grid"
)
.Columns(columns =>
{
columns.Bound(
"id"
).Groupable(
false
);
columns.Bound(
"firstName"
);
columns.Bound(
"lastName"
);
columns.Template(@<text></text>).ClientTemplate(
"#=myFunc()#"
).Width(120).Title(
"Year of birth"
);
})
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(
false
)
)
.Pageable(page => page.PageSizes(
true
))
.Scrollable()
.Filterable()
.HtmlAttributes(
new
Dictionary<
string
,
object
>
{
{
"data-bind"
,
"source: personArr"
}
})
)
</div>
Everything is fine, but I can't sort my last column with template myFunc
How I can fix this ?