Date sorting Issue

6 posts, 0 answers
  1. harisa
    harisa avatar
    4 posts
    Member since:
    Apr 2013

    Posted 27 May 2014 Link to this post

    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..
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 29 May 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. harisa
    harisa avatar
    4 posts
    Member since:
    Apr 2013

    Posted 29 May 2014 in reply to Daniel Link to this post

    Hello,

    when i set the schema inside data source and set template as you mentioned.then null display in date column.
    kindly help me.
  5. harisa
    harisa avatar
    4 posts
    Member since:
    Apr 2013

    Posted 29 May 2014 in reply to Daniel Link to this post

    after date parsing Issue has been resolved..

    Thank you so much.
  6. Sahir
    Sahir avatar
    4 posts
    Member since:
    Jul 2016

    Posted 13 Aug Link to this post

    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

  7. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 17 Aug Link to this post

    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.
     
Back to Top
Kendo UI is VS 2017 Ready