We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

show timestamp in column as datetime

the data source for the grid I have one of the fields contains a Unix timestamp. whether there is an opportunity to show it as a date time?

7 Replies

RU Ragavee U S Syncfusion Team February 6, 2017 11:42 AM UTC

Hi Razgovorov, 

Thanks for your interest in Syncfusion products. 

You can parse the timestamp using ej.parseJSON method before assigning dataSource to Grid and using the format property of the grid columns, you can assign required format in which the date to be displayed. Please refer to the below demo sample. 





Regards, 
Ragavee U S. 



RM Razgovorov Mikhail February 8, 2017 08:37 PM UTC

Thanks for the answer, but I need more.
is it possible to display the timestamp as a date, for example, for such data
       var data1 = [
                    { "OrderID": 10253, "OrderDate": 1454756603000},
                    { "OrderID": 10253, "OrderDate": 1486379003000}
]
;


RU Ragavee U S Syncfusion Team February 9, 2017 08:56 AM UTC

Hi Razgovorov, 

Yes. We can achieve your requirement by extending the adaptor and parsing the value as Date using JavaScript new Date method and then assigning it as dataSource to Grid. 


In the above sample, we have extended the processResponse function of the JsonAdaptor and thus have parsed the value of “OrderDate” field as Date Object. 

Regards, 
Ragavee U S. 



RM Razgovorov Mikhail February 19, 2017 07:32 AM UTC

Thank you. This approach requires a crawl of all data.

Perhaps there is an extension that makes the inverse transform before sending data to the server?


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 20, 2017 01:14 PM UTC

Hi  Razgovorov, 

Query #1: Remote and Local Data 

While using the above solution to the local Data, it will traverse with the whole datasource. There is no other option. When you bind remote Data to the Grid, it will take only currentPage records. So it won’t affect the performance. 

Query #2:  Transform into timestamp before sending data to the server. 
 
If you want to transform the date into timestamp before sending data to the server, you can use “actionBegin” event of the grid. In the actionBegin event ,we can get the date in “args.data” and  we have changed the format of date and transform into timestamp by using getTime()  method. 

Please refer to the code example:- 

  <div id="Grid"></div> 
  <script type="text/javascript"> 
    $("#Grid").ejGrid({ 
        dataSource: new ej.DataManager({ json: data1, adaptor: new dateAdaptor() }), 
        allowPaging: true, 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
        toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, 
        columns: [ 
                 { field: "OrderID", headerText: "Order ID", width: 75, textAlign: ej.TextAlign.Right }, 
 
          { field: "OrderDate", headerText: "Order Date", width: 80, format: "{0:MM-dd-yyyy}", textAlign: ej.TextAlign.Right }, 
 
        ], 
        actionBegin: function (args) { 
            if (args.requestType == "save") { 
                var myDate = args.data.OrderDate; 
                myDate = ej.format(new Date(myDate), "MM-dd-yyyy"); 
                myDate1 = myDate.split("-"); 
                var newDate = myDate1[1] + "," + myDate1[0] + "," + myDate1[2]; 
                args.data.OrderDate = new Date(newDate).getTime(); 
            } 
        } 
    }); 
 
    </script> 


Please refer to the attached sample:- 

http://jsplayground.syncfusion.com/sxe0ja44 


Otherwise could you please share us the following details to find the cause of the issue.  

1.       Please share us both view and controller side code example. 
 
2.        Have you bind remote or local data to the Grid. 
 
       2.     Replication procedure for the issue. 

       3.     Screenshot/Video regarding the issue. 

       4.    If possible, please reproduce the issue in the previously attached sample and send us back. 

       5.    Have you faced any script error regarding this. If so, please share us stacktrace of the issue. 
 

The provided details will helps us to analyze and provide you solution as early as possible. 

  
Regards, 

Farveen sulthana T 



RM Razgovorov Mikhail March 8, 2017 06:35 AM UTC

Thanks for the quick and comprehensive answer.
I understood the possibilities.
There is no problem. I'm considering use cases.


AS Alan Sangeeth S Syncfusion Team March 9, 2017 06:43 AM UTC

Hi Razgovorov, 
  
Thanks for the update. 
  
Please let us know if you have any other queries. We will be happy to help you. 
  
Regards,
Alan Sangeeth S 


Loader.
Up arrow icon