Home > front end >  Sorting date in yyyy/mm/dd format in Ajax and C#
Sorting date in yyyy/mm/dd format in Ajax and C#

Time:02-10

I want to sort out the date in yyyy/mm/dd format internally. Currently sorting is working based on day. DisplayDate is showing in the front end.But as I mentioned, I want to sort out internally in the above format so when user sort it, it will sort out based on yyyy/mm/dd format.

I tried changing to CAST(CreationDate, DateTime) in the query but it did not work.

C# code

   string query =                  
        @"             
        select CASE WHEN creationTime is null THEN '1900-01-01' ELSE creationTime END as creationTime
        from [Entry] doc"; 
        
        list.Add(new Doc()
                        {                                                               
                            CreationTime = reader.GetDateTime(reader.GetOrdinal("creationTime")),
                            DisplayDate = reader.GetDateTime(reader.GetOrdinal("creationTime")).ToString("dd/MM/yyyy").Replace('-', '/')                                  
                        });

JavaScript code

 $.ajax({
                type: 'GET',
                url: baseUrl,
                dataType: 'json',
                accept: 'application/json',
                contentType: "application/json; charset=utf-8",
                success: function (data, text) {
                    $("#Grid").jGrid({
                        width: "100%",
                        height: "620px",                     
                        sorting: true,
                        filtering: true,
                        paging: true,
                        pageSize: 15,
                        pageButtonCount: 5,
                        autoload: true,

                        data: data,
                        controller: {
                            loadData: function (filter) {
                                return $.grep(data, function (item) {                                 
                                    return                                         
                                        (!filter.displayDate || item.displayDate.indexOf(filter.displayDate) > -1);
                                });
                            }

CodePudding user response:

  •  Tags:  
  • Related