JavaScript/jQuery Chat Options
activeStateEnabled
The UI component switches to the active state when users press down the primary mouse button. When this property is set to true, the CSS rules for the active state apply. You can change these rules to customize the component.
Use this property when you display the component on a platform whose guidelines include the active state change for UI components.
dataSource
Chat works with collections of objects or string
values.
Depending on your data source, bind Chat to data as follows.
Data Array
Assign the array to the dataSource option.Read-Only Data in JSON Format
Set the dataSource property to the URL of a JSON file or service that returns JSON data.OData
Implement an ODataStore.Web API, PHP, MongoDB
Use one of the following extensions to enable the server to process data according to the protocol DevExtreme UI components use:Then, use the createStore method to configure access to the server on the client as shown below. This method is part of DevExtreme.AspNet.Data.
JavaScript- $(function() {
- let serviceUrl = "https://url/to/my/service";
- $("#chatContainer").dxChat({
- // ...
- dataSource: DevExpress.data.AspNet.createStore({
- key: "ID",
- loadUrl: serviceUrl + "/GetAction",
- insertUrl: serviceUrl + "/InsertAction",
- updateUrl: serviceUrl + "/UpdateAction",
- deleteUrl: serviceUrl + "/DeleteAction"
- })
- })
- });
Any other data source
Implement a CustomStore.
Regardless of the data source on the input, the Chat always wraps it in the DataSource object. This object allows you to sort, filter, group, and perform other data shaping operations. To get its instance, call the getDataSource() method.
Review the following notes about data binding:
Do not specify the items property if you specified the dataSource, and vice versa.
Data field names cannot be equal to
this
and should not contain the following characters:.
,:
,[
, and]
.
- The stores are immutable. You cannot change their configurations at runtime. Instead, create a new store or DataSource and assign it to the dataSource property as shown in the following help topic: Get and Set Properties.
elementAttr
Specifies the global attributes to be attached to the UI component's container element.
height
This property accepts a value of one of the following types:
Number
The height in pixels.String
A CSS-accepted measurement of height. For example,"55px"
,"20vh"
,"80%"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
items
messageTemplate
Name | Type | Description |
---|---|---|
component | dxChat |
The Chat instance. |
message |
The message text. |
The message's container. It is an HTML Element or a jQuery Element when you use jQuery.
- $(() => {
- const chat = $("#chat").dxChat({
- messageTemplate: (data, $container) => {
- return data.message.id + " " + data.message.text;
- },
- }).dxChat('instance');
- });
onDisposing
A function that is executed before the UI component is disposed of.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component | Chat |
The UI component's instance. |
onInitialized
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component | Chat |
The UI component's instance. |
onMessageEntered
Name | Type | Description |
---|---|---|
component | Chat |
The UI component's instance. |
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
message |
The entered message. |
Use this function to transfer messages to the backend:
- $(() => {
- function sendToBackend(message, chat) {
- console.log(`Message sent to backend: ${message.text}`);
- // Backend logic goes here
- }
- const chat = $("#chat").dxChat({
- onMessageEntered: (e) => {
- sendToBackend(e.message, chat);
- },
- }).dxChat('instance');
- });
onOptionChanged
Name | Type | Description |
---|---|---|
value | any |
The modified property's new value. |
previousValue | any |
The modified property's previous value. |
name |
The modified property if it belongs to the first level. Otherwise, the first-level property it is nested into. |
|
fullName |
The path to the modified property that includes all parent properties. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component | Chat |
The UI component's instance. |
onTypingEnd
Name | Type | Description |
---|---|---|
component | Chat |
The UI component's instance. |
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
user |
The user who entered the message. |
onTypingStart
Name | Type | Description |
---|---|---|
component | Chat |
The UI component's instance. |
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
user |
The user who started typing. |
reloadOnChange
Specifies whether the Chat UI component displays newly entered messages immediately. This property only applies if dataSource is used.
When you send a message in a Chat (press the "Send" button), the Chat triggers the store's insert method and adds the message to the store.
If reloadOnChange is enabled (default), the dataSource reloads: clears all items and calls the load method to update itself. Chat automatically listens to dataSource changes and updates the message feed with new messages.
Disable reloadOnChange to manage large numbers of messages, prevent additional load requests, and control message rendering timing. Handle the store's CRUD operations and render messages as your needs dictate.
rtlEnabled
When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.
- DevExpress.config({
- rtlEnabled: true
- });
typingUsers
The following image displays messages that appear when a single user or multiple users are typing:
- $(() => {
- const user = [{
- name: 'User'
- }];
- const chat = $("#chat").dxChat({
- onTypingStart:(e) => {
- e.component.option("typingUsers", user);
- },
- onTypingEnd:(e) => {
- e.component.option("typingUsers", []);
- },
- }).dxChat('instance');
- });
user
This property value, or its part, may be specified automatically:
If you do not specify this property, the component creates a user with default settings.
If you assign an object without an ID to this property, an ID is autogenerated.
width
This property accepts a value of one of the following types:
Number
The width in pixels.String
A CSS-accepted measurement of width. For example,"55px"
,"20vw"
,"80%"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.