Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kendo observable array sorting

Tags:

kendo-ui

I have a observable array in a viewmodel. I show the date of array with a template:

<table align="center">   
  <thead>
    <tr>
      <th>Name</th>
      <th>Surname</th>
   </tr>
  </thead>
  <tbody data-template="row-template" data-bind="source: client"></tbody> 
</table>

But if i want to sort array? and show the 'client' order by name or surname?

like image 579
Ciccio Avatar asked Nov 29 '25 02:11

Ciccio


1 Answers

If your data array is like this (as json, if not convert to json or databind using server)

[{name:'name1',surname:'surname1'},{name:'name2',surname:'surname2'},{name:'name3',surname:'surname3'}]

You can use this code for client side sorting.

$("table").kendoGrid({
  dataSource: {
     data:[{name:'name1',surname:'surname1'},{name:'name2',surname:'surname2'},{name:'name3',surname:'surname3'}],
     sort: {
        field: "name",
        dir: "desc"
     }
  },
  sortable: true,
  columns: [
     {
        field: "name",
        title: "Name"
     },
     {
        field: "surname",
        title: "Surname"
     }
  ]});

If i understand you right, this will solve your problem.

like image 187
Brend Avatar answered Dec 02 '25 05:12

Brend



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!