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

Displaying date and time in the chat dialog

2 Answers 28 Views
Chat
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Apr 2021, 10:36 PM
Hello - I am using the kendo ui asp.net mvc chat tool to provide a peer to peer chat solution for one of my projects. One of the requirements I have is to keep a log of the messages and then when the chat is initialized load a history of the messages for the last X number of days. I know that when you click on a conversation bubble in the chat box it displays the time the message was posted, but because the messages may span several days, I need a way to display both the date and the time the message was posted. Is there a way to do this? 

2 Answers, 1 is accepted

Sort by
0
Accepted
Neli
Telerik team
answered on 15 Apr 2021, 03:29 PM

Hi Chris,

A possible approach to add the full date to each rendered message is to use custom templates for the text and message as in the example below:

 

 var TEXT_MESSAGE_TEMPLATE = kendo.template(
          '<div class="#=styles.message#">' +
          '<time class="#=styles.messageTime#">#= kendo.toString(kendo.parseDate(timestamp), "MM/dd/yyyy HH:mm:ss") #</time>' +
          '<div class="#=styles.bubble#">#:text#</div>' +
          '</div>');

        kendo.chat.registerTemplate("text", TEXT_MESSAGE_TEMPLATE);
        
        kendo.chat.registerTemplate("message", TEXT_MESSAGE_TEMPLATE);

If needed, you can reduce the font of the date using the following CSS:

 .k-message-time {
          font-size:10px !important;
        }

The Dojo linked here demonstrates the approach described above.

Let me know in case you have additional questions on the matter.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Chris
Top achievements
Rank 1
answered on 17 Apr 2021, 01:44 AM
Thanks Neli. I think this will work. I will give it a try. 
Tags
Chat
Asked by
Chris
Top achievements
Rank 1
Answers by
Neli
Telerik team
Chris
Top achievements
Rank 1
Share this question
or