Kendo grid sort not working when the array contents are observable

1 Answer 237 Views
Data Source General Discussions Grid Sortable Templates
Jason
Top achievements
Rank 1
Jason asked on 18 Nov 2021, 02:31 PM | edited on 19 Nov 2021, 07:55 AM

Hi,
I have an observable array of observables which is linked to a kendo grid as datainput. I am trying to sort it by clicking on column header. I have made the sortable : true. But the issue is when the array is 

self.array = ko.observableArray([{ Cabin: 'eco' }, { Cabin: 'taper' }]); The sorting works

But If the array is 
self.AllocArray = ko.observableArray([{ Cabin: ko.observable('eco') }, { Cabin: ko.observable('taper') }]); then the sorting doesn't work.

Is there any possible solution around this?

Many thanks,

Jason

1 Answer, 1 is accepted

Sort by
1
Accepted
Veselin Tsvetanov
Telerik team
answered on 23 Nov 2021, 01:50 PM

Hi Jason,

The Kendo logic will automatically convert all members of an ObservableArray to ObservableObjects. If you run the following snippet:

var array = new kendo.data.ObservableArray([{ Cabin: 'eco' }, { Cabin: 'taper' }]);
alert('are members of array instances of ObservableObject? ' + (array[0] instanceof kendo.data.ObservableObject));

you will see that in action. Having that said, you should never initialize the ObservableArray members as ObservableObjects. That would result in issues as described.

Regards,
Veselin Tsvetanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Data Source General Discussions Grid Sortable Templates
Asked by
Jason
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or