JavaScript/jQuery Lookup - Enable Grouping
The Lookup can organize items in groups. If you use a simple array as a data source, its objects must have the key and items fields.
- const lookupData = [{
- key: "Mr. John Heart",
- items: ["Google AdWords Strategy", "New Brochures", "Update NDA Agreement"]
- }, {
- key: "Mrs. Olivia Peyton",
- items: ["Update Personnel Files", "Non-Compete Agreements", "Give Final Approval for Refunds"]
- }, // ...
- ];
- $(function() {
- $("#lookupContainer").dxLookup({
- dataSource: lookupData,
- grouped: true
- });
- });
If you use the DevExtreme DataSource, specify its group property. In both cases, you need to make the Lookup know that its data source is grouped by assigning true to the grouped property.
- const lookupData = [
- { name: "Amelia", birthYear: 1991, gender: "female" },
- { name: "Benjamin", birthYear: 1983, gender: "male" },
- { name: "Andrew", birthYear: 1991, gender: "male" },
- { name: "Daniela", birthYear: 1983, gender: "female" },
- { name: "Lee", birthYear: 1983, gender: "male" },
- { name: "Betty", birthYear: 1983, gender: "female" }
- ];
- $(function() {
- $("#lookupContainer").dxLookup({
- dataSource: new DevExpress.data.DataSource({
- store: lookupData,
- group: "gender"
- }),
- grouped: true,
- displayExpr: "name",
- valueExpr: "name"
- });
- });
To customize group headers, specify a groupTemplate. In Angular and Vue, you can declare it in the markup. In React, you can use a rendering function (shown in the code below) or component:
If you use jQuery alone, use DOM manipulation methods to combine the HTML markup for items. To apply this markup, use the itemTemplate callback function as shown in the following code.
- const lookupData = [{
- key: "Mr. John Heart",
- items: ["Google AdWords Strategy", "New Brochures", "Update NDA Agreement"]
- }, {
- key: "Mrs. Olivia Peyton",
- items: ["Update Personnel Files", "Non-Compete Agreements", "Give Final Approval for Refunds"]
- }, // ...
- ];
- $(function() {
- $("#lookupContainer").dxLookup({
- dataSource: lookupData,
- grouped: true,
- groupTemplate: function (data) {
- return $("<div>Assigned: " + data.key + "</div>");
- }
- });
- });
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.