DevExtreme React - 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.

NOTE
Only one-level grouping is supported.

If you use the DevExtreme DataSource, specify its group option. In both cases, you need to make the Lookup know that its data source is grouped by assigning true to the grouped option.

You can define a custom template for the group headers. For Angular, AngularJS and Knockout apps, DevExtreme provides a markup component called dxTemplate. The following code shows how you can use dxTemplate to define a template for the Lookup group headers.

If you use jQuery alone, combine the HTML markup for items manually with jQuery DOM manipulation methods. To apply this markup, use the itemTemplate callback function as shown in the following code.

JavaScript
  • var 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