Set Date on renderMessage in KendoChat

1 Answer 7 Views
Chat
Richard
Top achievements
Rank 1
Veteran
Richard asked on 11 Nov 2021, 07:29 PM

Is there a way to set the date on the renderMessage method.  I'm using the renderMessage to pre-populate the chat instance with a predefined, persistent chat message.  When you click on the chat bubble, it shows you the time in hh:mm:ss format.

I'm curious, is there a way to set the date on the renderMessage.  If yes, can you control what shows up when you click on it (i.e. old stuff, you most likely want to see the time.

Thanks,

Richard

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 16 Nov 2021, 08:46 AM

Hello, Richard,

A possible approach would be to register a new template that would render a date in a specified format along with the text of the message. Here is a small example on how to do it.

Let me know if that works for you.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Richard
Top achievements
Rank 1
Veteran
commented on 16 Nov 2021, 01:28 PM

Martin - 

Thanks!  I think that will work.  I last question!  When you click on a bubble (selected) it creates a small gap.  This is similar to how iMessage and Android work.  There, the UI allows you to place "text" that is only visible when you select the bubble.  Curious if there is any way to control, programmatically via the template, what goes into that space that would only be visible upon click.

Thanks,

Richard

Martin
Telerik team
commented on 19 Nov 2021, 10:02 AM

The gap you are referring to is simply a margin-bottom style applied to the selected item. A possible approach to show some text there would be to have an additional HTML element (initially hidden) in the template:
    <script id="quote-template" type="text/x-kendo-template">
      <div class="#=styles.message#">
        <time class="#=styles.messageTime#">#= kendo.toString(kendo.parseDate(customTimestamp), "MM/dd/yyyy HH:mm:ss") #</time>
        <div class="#=styles.bubble#">#:text#</div>
        <span class='textWrapper' style="display:none">some text</span>
      </div>
    </script>
Then you can bind to the document.click event and check if the target has the k-bubble class. If it does, use the show() method to make the text visible. Here is a small example of the suggestion above. Let me know if that works for you.
Tags
Chat
Asked by
Richard
Top achievements
Rank 1
Veteran
Answers by
Martin
Telerik team
Share this question
or