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

Grid with template not sorting correctly

1 Answer 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 11 Mar 2013, 03:24 PM
Hi, i have a grid which is not sorting correctly. I am using a template to define columns. I think the issue is that the column sort value/field for the individual columns is not explicitly defined so i don't see how the grid would know what to sort on. How can i define which field each column in my template should sort on?

$("#listGrid").kendoGrid({
            rowTemplate: kendo.template($("#detailsTemplate").html().replace('k-alt', '')),
            altRowTemplate: kendo.template($("#detailsTemplate").html()),
            scrollable: false,
            dataSource: {
                transport: {
                    read: url
                },
                schema: {
                    model: {
                        fields: {
                            ItemId: { type: "number", sortable: true },
                            ItemName: { type: "string", sortable: true },
                            Created: { type: "date", sortable: true },
                            Modified: { type: "date", sortable: true },
                            OwnerName: { type: "string", sortable: true },
                            OwnerId: { type: "number", sortable: true }
                        }
                    }
                }
            },
            sortable:true
        });


<script id="detailsTemplate" type="text/x-kendo-template">
        
    <tr class="row k-alt">
        <td>
             <a href="/Members/Chart.aspx?costDriverId=#=ItemId#">#= ItemName#</a>
        </td>
        <td>
             #= kendo.toString(Created, "dd/MM/yyyy") #
        </td>
        <td>
              #= kendo.toString(Modified, "dd/MM/yyyy") #
        </td>
        <td>
        #if(OwnerId.toString() == userInfo.UserId){#
            Me
        #}else{#
            #:OwnerName#
        #}#
        </td>
        <td>
          <a class="copyLink" onclick="copyCustomData(#=ItemId#, this) href="\#">Copy</a>
        </td>
        <td>           
             #if((OwnerId.toString() == userInfo.UserId) || (userInfo.IsGAM == true)){#
                <a class="editLink" href="/CustomData/?id=#=ItemId#">Edit</a>
            #}#               
        </td>
        <td>
            #if((OwnerId.toString() == userInfo.UserId) || (userInfo.IsGAM == true)){#
                <a href="\#" onclick="deletePricingModel(#=ItemId#, this);return false;"><img src="/Content/images/member/delete_icon.gif" alt="Delete" /></a>
            #}#                            
        </td>
        <td>
            #if((OwnerId.toString() == userInfo.UserId) || (userInfo.IsGAM == true)){#
                <a href="\#" onclick="sharePricingModel(#=ItemId#);return false;"><img src="/Content/images/member/iconShare.gif" alt="Manage Sharing" /></a>
            #}#               
        </td>
    </tr>
    
    
    </script>



1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Mar 2013, 11:44 AM
Hello Rich,

You can still define the columns when using a row template e.g.

$("#listGrid").kendoGrid({
    rowTemplate: kendo.template($("#detailsTemplate").html().replace('k-alt', '')),
    altRowTemplate: kendo.template($("#detailsTemplate").html()),
    scrollable: false,
    columns: ["ItemName","Created", "Modified", "OwnerName",{title: "Copy"}, {title: "Edit"}, {title: "Delete"}, {title: "Share"}],
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or