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

Date sorting Issue

5 Answers 363 Views
Grid
This is a migrated thread and some comments may be shown as answers.
harisa
Top achievements
Rank 1
harisa asked on 27 May 2014, 11:32 AM
Sorting by date issue..

<table id="grid">
                <thead>
                    <tr>
 <th>SNO</th>
                        <th data-field="NAME">NAME</th>
                        <th data-field="EMPID">EMPID</th>
                        <th data-field="CATEGORY">CATEGORY</th>  
                        <th data-field="SUBCATEGORY">SUBCATEGORY</th>  
                        <th data-field="CONTACTDURING">CONTACTDURING</th>  
                        <th data-field="DEPARTMENT">DEPARTMENT</th>  
                        <th data-field="SUBDEPARTMENT">SUBDEPARTMENT</th>  
                        <th data-field="STATUS">STATUS</th>  
                        <th data-field="datefrom">FROM DATE</th>
                        <th data-field="TODATE">TO DATE</th>
                        <th data-field="TOTALDAYS">TOTALDAYS</th>
                        <th data-field="DEATHCATEGORY">DEATHCATEGORY</th>                         
                    </tr>
                </thead>
                <tbody>
                   <?php
$i=1;

                       foreach($leaveInfo as $records){  
                           $newDate = date("d/M/y", strtotime( $records['FROMDATE']));
                           $newDate1 = date("d/M/y", strtotime( $records['TODATE']));
                           ?>                  
                           <tr>
                      <td></td>
                      <td><a href="<?php echo $this->baseUrl()?>/index/employeeprofile/id/<?php echo $records['EMPID']?>"><?php echo $records['NAME']?></a></td>                      <td><?php echo $records['EMPID']?></td>
                      <td><?php echo $records['CATEGORY']?></td>
                      <td><?php echo $records['SUBCATEGORY']?></td>
                      <td><?php echo $records['CONTACTDURING']?></td>
                      <td><?php echo $records['DEPARTMENT']?></td>
                      <td><?php echo $records['SUBDEPARTMENT']?></td>
                      <td><?php echo $records['STATUS']?></td>
                      <td><?php echo $newDate;?></td>
                      <td><?php echo $newDate1;?></td>
                      <td><?php echo $records['TOTALDAYS']?></td>
                      <td><?php echo $records['DEATHCATEGORY']?></td>
                           </tr>              
                   <?php }?>
                </tbody>
</table>
<?php }else{   echo "</br></br><div align='center'><h2>No Leave Record Found</h2></div>";
}?>
<script type="text/javascript">
 var record=0;
$("#grid").kendoGrid({
        schema: {
        model: {
            fields: {
SNO: { type: "number"},
                NAME: { type: "string"},
                EMPID: { type: "string"},  
                CATEGORY: { type: "string" },  
                SUBCATEGORY: { type: "string" },  
                CONTACTDURING: { type: "string" },  
                DEPARTMENT: { type: "string" },  
                SUBDEPARTMENT: { type: "string" },
                STATUS: { type: "string" },
                datefrom: { type: "date" },  
                TODATE: { type: "date" },  
                TOTALDAYS: { type: "string" },
                DEATHCATEGORY: { type: "string" }  
                  
                
            }
            
        }
    },
    groupable: true,
    navigatable: true,
    columnMenu: true,
    columns: [
     {
         title: "&nbsp;",
         template: "#= ++record #",
         width: 60
       
    },
 {
        field: "NAME",
        title: "NAME",
       
    },
 
    {
        field: "EMPID",
        title: "EMPID",
       
    },
    {
        field: "CATEGORY",
        title: "CATEGORY",
       
    },
    {
        field: "SUBCATEGORY",
        title: "SUBCATEGORY",
       
    },
    {
        field: "CONTACTDURING",
        title: "CONTACTDURING",
       
    },
    {
        field: "DEPARTMENT",
        title: "DEPARTMENT",
       
    },
    {
        field: "SUBDEPARTMENT",
        title: "SUBDEPARTMENT",
       
    },
    {
        
        field: "STATUS",
     title: "STATUS",
       
       
    },
    {
         field: "datefrom",
         title: "FROMDATE",
         template: '#= kendo.toString(kendo.parseDate(datefrom, "dd/MMM/yy"), "dd/MMM/yy") #'
         //format: "{0:dd/MMM/yy}"
           
        },  
    {
        
          field: "TODATE",
        title: "TODATE",
        template: '#= kendo.toString(kendo.parseDate(TODATE, "dd/MMM/yy"), "dd/MMM/yy") #'
        //format: "{0:yy}",
      },
      {
          field: "TOTALDAYS",
          title: "TOTALDAYS",
          
         
      },
     
    
    {
       
        field: "DEATHCATEGORY",
     title: "DEATHCATEGORY",
    }
],
 
    scrollable: true,
    navigatable: true,
    sortable: true,
    filterable: true,
    editable: "popup",
    
    dataBinding: function() {
        record = 0;
       
      }
   });

in above code from date and to date is not sorting  properly..

Please help..

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 May 2014, 08:48 AM
Hello,

The problem will occur because the schema is set to the grid instead of the grid dataSource. Thus, the dataSource will not know the fields types and will not parse the values so it will sort them as strings. Setting the schema to the dataSource:
$("#grid").kendoGrid({
    dataSource: {
        schema: {
            ...
should resolve the problem. Parsing the dates in the templates should also be necessary in this case:
template: '#= kendo.toString(datefrom, "dd/MMM/yy") #'



Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
harisa
Top achievements
Rank 1
answered on 29 May 2014, 10:04 AM
Hello,

when i set the schema inside data source and set template as you mentioned.then null display in date column.
kindly help me.
0
harisa
Top achievements
Rank 1
answered on 29 May 2014, 11:23 AM
after date parsing Issue has been resolved..

Thank you so much.
0
Sahir
Top achievements
Rank 1
answered on 13 Aug 2016, 01:16 PM

I have tried so many things nothing works here.kindly explain me why?

 

https://www.telerik.com/account/support-tickets/view-ticket?threadid=1056679

https://stackoverflow.com/questions/38896594/why-kendo-ui-grid-date-is-not-sorting-properly

0
Daniel
Telerik team
answered on 17 Aug 2016, 06:43 AM
Hello,

Could you provide the full code that you are using for the grid and the dataSource? I checked the ticket and the stackoverflow question but there are some inconsistencies in the code like the model definition. My only guess based on the provided code is that the model definition is not correct and the string is not parsed to a Date by the dataSource. This is also indicated by the fact that you need to parse the value in the custom compare function:
sortable:{ 
    compare: function (a, b) {
        var c = new Date(a.ReinsDepositDate);
        var d = new Date(b.ReinsDepositDate);
        return c - d;
    }


Regards,
Daniel
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
harisa
Top achievements
Rank 1
Answers by
Daniel
Telerik team
harisa
Top achievements
Rank 1
Sahir
Top achievements
Rank 1
Share this question
or