I have a Kendo grid on a MVC .cshtml view page:
@model IEnumerable<Models.GetItems>
<script>
$(document).ready(function () {
$("#grid").kendoGrid({
sortable: true
});
});
</script> <table class="table" id="grid">
<thead>
<tr>
<th data-field="Quantity">
Qty
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink(item.Quantity.ToString(), "kendo", "Groups", new { ID = item.ID }, null)
</td>
</tr>
}
</tbody>
</table>
It displays the way I want; as a number with a link to a drill down page, but the sorting doesn't work at all.
How can I tell the grid I want the data type to be a number so it can sort it like a number?
(item.Quantity is Int16 from the model, but had to make it a string for the ActionLink to work)
(I'm open to binding the grid differently if I have to (bind to json output from controller and/or use rowTemplate and/or bind to empty div and define columns in JS possibly with template), but not sure at this point if that will matter, seems like a data type issue regardless of binding method???)
@model IEnumerable<Models.GetItems>
<script>
$(document).ready(function () {
$("#grid").kendoGrid({
sortable: true
});
});
</script> <table class="table" id="grid">
<thead>
<tr>
<th data-field="Quantity">
Qty
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink(item.Quantity.ToString(), "kendo", "Groups", new { ID = item.ID }, null)
</td>
</tr>
}
</tbody>
</table>
It displays the way I want; as a number with a link to a drill down page, but the sorting doesn't work at all.
How can I tell the grid I want the data type to be a number so it can sort it like a number?
(item.Quantity is Int16 from the model, but had to make it a string for the ActionLink to work)
(I'm open to binding the grid differently if I have to (bind to json output from controller and/or use rowTemplate and/or bind to empty div and define columns in JS possibly with template), but not sure at this point if that will matter, seems like a data type issue regardless of binding method???)
7 Answers, 1 is accepted
0
Hi Chad,
The field's type could be specified using the data-type attribute, as shown in this example. Since you are using the the ASP.NET MVC wrappers, I would also recommend checking the Grid Server Binding article.
Regards,
Alexander Popov
Telerik
The field's type could be specified using the data-type attribute, as shown in this example. Since you are using the the ASP.NET MVC wrappers, I would also recommend checking the Grid Server Binding article.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Chad
Top achievements
Rank 1
answered on 14 Aug 2014, 04:16 PM
[quote]Alexander Popov said:Hi Chad,
The field's type could be specified using the data-type attribute, as shown in this example. Since you are using the the ASP.NET MVC wrappers, I would also recommend checking the Grid Server Binding article.
Regards,
Alexander Popov
Telerik
[/quote]
Setting data-type="number" doesn't work, the data doesn't show up at all.
I have another grid with a similar issue, the data contains numbers SOMETIMES, other times it contains letters, setting data-type to number makes sorting work WHEN the data is numbers, but when it isn't the data dissappears just like in the example with the link...
The field's type could be specified using the data-type attribute, as shown in this example. Since you are using the the ASP.NET MVC wrappers, I would also recommend checking the Grid Server Binding article.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Setting data-type="number" doesn't work, the data doesn't show up at all.
I have another grid with a similar issue, the data contains numbers SOMETIMES, other times it contains letters, setting data-type to number makes sorting work WHEN the data is numbers, but when it isn't the data dissappears just like in the example with the link...
0

Chad
Top achievements
Rank 1
answered on 14 Aug 2014, 11:59 PM
more generically, is there a way to display one thing and sort by another?
0
Hello again Chad,
I am afraid that this scenario is not supported.
Regards,
Alexander Popov
Telerik
I am afraid that this scenario is not supported.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Chad
Top achievements
Rank 1
answered on 18 Aug 2014, 11:37 PM
I changed my grid to bind to a json service and got it working:
using the template I call a function that returns an image tag with a path to an image based on the status, so the image is shown, but sorting works based on status (which is a number) because of the value specified.
$(
function
() {
$(
"#divGrid"
).kendoGrid({
dataSource: {
transport: {
read:
"/Path/To/API/"
,
dataType:
"json"
},
pageSize: 15
},
pageable:
true
,
sortable:
true
,
filterable:
true
,
groupable:
true
,
columns: [
{ field:
"Status"
, value:
'#= Status #'
, template:
'<div style="text-align: center;">#= i(Status) #</div>'
, width: 80, filterable:
false
}]
});
});
using the template I call a function that returns an image tag with a path to an image based on the status, so the image is shown, but sorting works based on status (which is a number) because of the value specified.
0

Chad
Top achievements
Rank 1
answered on 18 Aug 2014, 11:42 PM
can you please change the read path to something generic, xxxxxx or whatever.
thanks!
thanks!
0
Accepted
Hi Chad,
Thank you for taking the time to share this solution. As you requested, I have edited the Read URL so it does not give out any private information.
Regards,
Alexander Popov
Telerik
Thank you for taking the time to share this solution. As you requested, I have edited the Read URL so it does not give out any private information.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!