Group items in popup in React Split button component

30 Jan 20235 minutes to read

Items in popup can be grouped in SplitButton by templating entire popup with ListView. To achieve grouping in ListView, check ListView grouping documentation. To template ListView in popup, create ListView with id listview and provide it as target for SplitButton.

The following example illustrates how to group items in popup using ListView component.

import { enableRipple } from '@syncfusion/ej2-base';
import { SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import { ListViewComponent } from '@syncfusion/ej2-react-lists';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render SplitButton.
function App() {
    // Datasource for listview.
    let listItems = [
        {
            'category': 'Basic',
            'text': 'Cut'
        },
        {
            'category': 'Basic',
            'text': 'Copy',
        },
        {
            'category': 'Basic',
            'text': 'Paste'
        },
        {
            'category': 'Advanced',
            'text': 'Paste as Formula'
        },
        {
            'category': 'Advanced',
            'text': 'Paste as Hyperlink'
        },
    ];
    let field = { groupBy: 'category' };
    return (<div>
       <ListViewComponent id="listview" dataSource={listItems} fields={field} sortOrder="Descending"/>
       <SplitButtonComponent target="#listview">ClipBoard</SplitButtonComponent>
      </div>);
}
export default App;
ReactDom.render(<App />, document.getElementById('button'));
import { enableRipple } from '@syncfusion/ej2-base';
import { SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import { ListViewComponent } from '@syncfusion/ej2-react-lists';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

// To render SplitButton.
function App() {

    // Datasource for listview.
    let listItems: Array<{ [key: string]: string; }> = [
        {
            'category': 'Basic',
            'text': 'Cut'
        },
        {
            'category': 'Basic',
            'text': 'Copy',
        },
        {
            'category': 'Basic',
            'text': 'Paste'
        },
        {
            'category': 'Advanced',
            'text': 'Paste as Formula'
        },
        {
            'category': 'Advanced',
            'text': 'Paste as Hyperlink'
        },
    ];

   let field: any = { groupBy: 'category' };
    return (
    <div>
       <ListViewComponent id="listview" dataSource={listItems} fields={field} sortOrder="Descending"/>
       <SplitButtonComponent target="#listview">ClipBoard</SplitButtonComponent>
      </div>
    );
}
export default App;
ReactDom.render(<App />,document.getElementById('button'));