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

Kendo grid MVC number link column sorting

7 Answers 237 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 12 Aug 2014, 04:04 PM
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???)

7 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 14 Aug 2014, 12:43 PM
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
 
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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
[/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...
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
Alexander Popov
Telerik team
answered on 15 Aug 2014, 09:45 AM
Hello again Chad,

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:

$(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!
0
Accepted
Alexander Popov
Telerik team
answered on 19 Aug 2014, 05:17 AM
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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Chad
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Chad
Top achievements
Rank 1
Share this question
or