sorting in kendo grid using custom values -


need sorting these json results days inside kendogrid. need way turn plus sign .5 or along lines. suppose have loop through each one, if find plus sign change value number.5 , drop new value in before displaying?

{ name: alex, days: "2" }, { name: jason, days: "1" }, { name: fred, days: "2+" }, { name: jane, days: "3" }, { name: john, days: "3+" } 

here code got working

<body>     <div id="grid">      </div>     <div>         <script>             $(document).ready(function () {                 //json data                  var people = [                 { firstname: "hasibul", lastname: "haque", email: "hasibul2363@gmail.com", rank:"2" }                 , { firstname: "jane", lastname: "smith", email: "jane.smith@kendoui.com", rank: "3+" }                 , { firstname: "jason", lastname: "doe", email: "hasibul2363@gmail.com", rank: "1" }                 , { firstname: "john", lastname: "doe", email: "hasibul2363@gmail.com", rank: "3+" }                 , { firstname: "joan", lastname: "doe", email: "hasibul2363@gmail.com", rank: "5" }                 , { firstname: "jack", lastname: "doe", email: "hasibul2363@gmail.com", rank: "3" }                  , { firstname: "jacob", lastname: "doe", email: "hasibul2363@gmail.com", rank: "3-" }                   , { firstname: "joe", lastname: "doe", email: "hasibul2363@gmail.com", rank: "3-" }                  ];                   $('#grid').kendogrid({                     datasource: {                         type: "json",                         data: people,                         pagesize: 15,                         sort: ({ field: "rank" })                     },                     sortable: true,                     columns:[{                         field: "rank",                         sortable: {                             compare: function (a, b, asc) {                                  var s1 = a.rank;                                 var s2 = b.rank;                                  var n1, n2;                                 var sg1, sg2;                                  var plus = s1.indexof('+');                                 var minus = s1.indexof('-');                                  if(plus >= 0){                                     n1 = parseint(s1.substr(0, plus));                                     sg1 = 1;                                 }                                 else if(minus >= 0){                                     n1 = parseint(s1.substr(0, minus));                                     sg1 = -1;                                 }                                 else{                                     n1 = parseint(s1);                                     sg1 = 0;                                 }                                  plus = s2.indexof('+');                                 minus = s2.indexof('-');                                  if (plus >= 0) {                                     n2 = parseint(s2.substr(0, plus));                                     sg2 = 1;                                 }                                 else if (minus >= 0) {                                     n2 = parseint(s2.substr(0, minus));                                     sg2 = -1;                                 }                                 else {                                     n2 = parseint(s2);                                     sg2 = 0;                                 }                                  if (n1 == n2) {                                     return sg2 - sg1;                                 } else {                                     return n2 - n1;                                 }                             }                         }                     }]                                                                 ,                     pageable: {                          buttoncount: 1                     },                     schema: {                         data: "people"                      }                     //binding json data grid                  });                 });         </script> 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -