DevExtreme v24.2 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

JavaScript/jQuery Chat - Customization

Use the following properties to customize the DevExtreme JavaScript Chat component:

Backend API
$(() => { const chat = $('#chat').dxChat({ height: 710, items: messages, user: currentUser, dayHeaderFormat: dayHeaderFormats[0], messageTimestampFormat: messageTimestampFormats[0], onMessageEntered({ component, message }) { component.renderMessage(message); }, }).dxChat('instance'); $('#show-avatar').dxCheckBox({ value: true, text: 'Avatar', onValueChanged(data) { chat.option('showAvatar', data.value); }, }); $('#show-user-name').dxCheckBox({ value: true, text: 'User Name', onValueChanged(data) { chat.option('showUserName', data.value); }, }); $('#show-day-headers').dxCheckBox({ value: true, text: 'Day Headers', onValueChanged(data) { chat.option('showDayHeaders', data.value); }, }); $('#day-header-format').dxSelectBox({ items: dayHeaderFormats, value: dayHeaderFormats[0], inputAttr: { 'aria-label': 'Day Header Format' }, onValueChanged(data) { chat.option('dayHeaderFormat', data.value); }, }); $('#show-message-timestamp').dxCheckBox({ value: true, text: 'Message Timestamp', onValueChanged(data) { chat.option('showMessageTimestamp', data.value); }, }); $('#message-timestamp-format').dxSelectBox({ items: messageTimestampFormats, value: messageTimestampFormats[0], inputAttr: { 'aria-label': 'Message Timestamp Format' }, onValueChanged(data) { chat.option('messageTimestampFormat', data.value); }, }); $('#chat-disabled').dxCheckBox({ value: false, text: 'Disable Chat', onValueChanged(data) { chat.option('disabled', data.value); }, }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.2.7/css/dx.light.css" /> <script src="js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="data.js"></script> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="chat-container"> <div id="chat"></div> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <div id="show-avatar"></div> </div> <div class="option"> <div id="show-user-name"></div> </div> <div class="option-separator"></div> <div class="option"> <div id="show-day-headers"></div> </div> <div class="option"> <span>Day Header Format:</span> <div id="day-header-format"></div> </div> <div class="option-separator"></div> <div class="option"> <div id="show-message-timestamp"></div> </div> <div class="option"> <span>Message Timestamp Format:</span> <div id="message-timestamp-format"></div> </div> <div class="option-separator"></div> <div class="option"> <div id="chat-disabled"></div> </div> </div> </div> </body> </html>
.demo-container { min-width: 720px; display: flex; gap: 20px; } .chat-container { display: flex; flex-grow: 1; align-items: center; justify-content: center; } .options { padding: 20px; display: flex; flex-direction: column; min-width: 280px; background-color: rgba(191, 191, 191, 0.15); gap: 16px; } .dx-chat { max-width: 480px; } .caption { font-size: var(--dx-font-size-sm); font-weight: 500; } .option-separator { border-bottom: 1px solid var(--dx-color-border); } .dx-avatar { border: 1px solid var(--dx-color-border); }
const getTimestamp = function (date, offsetMinutes = 0) { return date.getTime() + offsetMinutes * 60000; }; const date = new Date(); date.setHours(0, 0, 0, 0); const currentUser = { id: 'c94c0e76-fb49-4b9b-8f07-9f93ed93b4f3', name: 'John Doe', }; const supportAgent = { id: 'd16d1a4c-5c67-4e20-b70e-2991c22747c3', name: 'Support Agent', avatarUrl: '../../../../images/petersmith.png', }; const messages = [ { timestamp: getTimestamp(date, -9), author: supportAgent, text: 'Hello, John!\nHow can I assist you today?', }, { timestamp: getTimestamp(date, -7), author: currentUser, text: "Hi, I'm having trouble accessing my account.", }, { timestamp: getTimestamp(date, -7), author: currentUser, text: 'It says my password is incorrect.', }, { timestamp: getTimestamp(date, -7), author: supportAgent, text: 'I can help you with that. Can you please confirm your UserID for security purposes?', }, { timestamp: getTimestamp(date, 1), author: currentUser, text: 'john.doe1357', }, { timestamp: getTimestamp(date, 1), author: supportAgent, text: '✅ Instructions to restore access have been sent to the email address associated with your account.', }, ]; const dayHeaderFormats = ['dd/MM/yyyy', 'dd.MM.yyyy', 'MMMM dd, yyyy', 'EEEE, MMMM dd']; const messageTimestampFormats = ['hh:mm a', 'hh:mm:ss a', 'HH:mm', 'HH:mm:ss'];