Search results

Get the total count of data when remote data bind with DropDownList in React DropDownList component

11 Jan 2022 / 2 minutes to read

Before component rendering, you can get the total items count by using actionComplete  event with its result arguments.

After rendering this component, you can get the total items count by using getItems method.

The following example demonstrate how to get the total items count.

Copied to clipboard
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

export default class App extends React.Component<{}, {}> {
  // bind the DataManager instance to dataSource property
  private customerData: DataManager = new DataManager({
    adaptor: new ODataV4Adaptor,
    crossDomain: true,
    url: ''
  private dropDownListObject: any;
  // bind the Query instance to query property
  private query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
  // maps the appropriate column to fields property
  private fields: object = { text: 'ContactName', value: 'CustomerID' };
  // sort the resulted items
  private sortOrder: string = 'Ascending';
  constructor(props: any) {
    this.onclick = this.onclick.bind(this);
  public onActionComplete(e: any) {
    // get total items count
    console.log("Total items count: " + e.result.length);
    const element: HTMLElement = document.createElement('p');
    element.innerText = "Total items count: " + e.result.length;
    (document.getElementById('event') as any).append(element);
  public onclick() {
    // get items count using getItems method
    console.log("Total items count: " + this.dropDownListObject.listData.length);
    const element: HTMLElement = document.createElement('p');
    element.innerText = "Total items count: " + this.dropDownListObject.listData.length;
    (document.getElementById('event') as any).append(element);
  public render() {
    return (
      // specifies the tag for render the DropDownList component
        <DropDownListComponent ref={(scope) => { this.dropDownListObject = scope; }} id="ddlelement"
          query={this.query} dataSource={this.customerData}
          fields={this.fields} sortOrder={this.sortOrder} placeholder="Select a customer" actionComplete={this.onActionComplete} />
          <div id='event'/>
        <button id='btn' className="e-control e-btn" onClick={this.onclick}> Get items </button>
ReactDOM.render(<App />, document.getElementById('sample'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

    <title>Syncfusion React DropDownList</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
			margin: 50px;

    <div id='sample' style="margin: 20px auto 0; width:250px;">
        <div id='loader'>Loading....</div>
	<div id='event'></div>