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

Sorting a Grid bound to array...

2 Answers 250 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 1
Robin asked on 08 Jul 2014, 03:49 PM
Is it possible to set the sort of a grid that is bound to a simple array ?  I know I could make the array into a dataSource and add sorting that way, but this array is a child of an object which the entire template is bound to, so I use the value bindings for a grid to the child array.

See jsbin sample http://jsbin.com/haciba/1/edit 

Do I need to sort this data ahead of time, before I create the observable, or is there a way to declaratively set the sorting on the grid ?

Thanks,

Robin

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 10 Jul 2014, 12:18 PM
Hi Robin,

Yes it is possible to set the sort order via data attributes. Please see the updated example:
<div id="grid"
  data-role="grid"
  data-sortable="true"
  data-columns="[{field: 'c', title: 'Color'},
  {field: 'order', title: 'Order'}]"
  data-source='{"sort": { "field": "order", "dir": "asc"}}'
  data-bind="source: colors">
</div>


Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Robin
Top achievements
Rank 1
answered on 10 Jul 2014, 12:26 PM
Thank you so much.  Works perfectly.
Tags
MVVM
Asked by
Robin
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Robin
Top achievements
Rank 1
Share this question
or