C_sharp
C_sharp

Reputation: 418

How to sort Kendo grid on different field?

I have a KenodGrid and I have field whose data is combination of two fields from the data. How would I be able to sort the Column based on the data of one field. Here is the column I have:

   {
            field: "Owner",
            filterable: false,
            sortable: true,

            template: function(data) {
                return data.OwnerFirstName + ' ' + data.OwnerLastName;
            }
        },

I want to sort the column on either OwnerFirstName or OwnerLastName but want to display both in the grid.

Upvotes: 0

Views: 2908

Answers (2)

R.K.Saini
R.K.Saini

Reputation: 2708

Kendo grid sort table based on defined field for the column in configuration, using a template doesn't effect it. So if you add OwnerFirstName or OwnerLastName to your column field it will sort it will sort your table perfectly.

    columns: [
      { field: "OwnerFirstName",
       title:"owner",
            filterable: false,
            sortable: true,
            template: function(data) {
                return data.OwnerFirstName + ' ' + data.OwnerLastName;
            }
      },
    ....
  ]

Here is a working demo http://dojo.telerik.com/IPeVI

Upvotes: 2

JBO
JBO

Reputation: 270

You have to make it into 2 columns to be able to sort them apart :

            columns: [{
                field: "OwnerFirstName ",
                title: "Owner first name",
                filterable: false,
                sortable: true
            }, {
                field: "OwnerLastName",
                title: "Owner lastname",
                filterable: false,
                sortable: true
            }]

Upvotes: 1

Related Questions