Search on filtering in EJ2 TypeScript Drop down list control
2 May 20233 minutes to read
The following example demonstrates about how to set limit the search result on filtering.
import { DropDownList, FilteringEventArgs } from '@syncfusion/ej2-dropdowns';
import { Query, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data';
let searchData: DataManager = new DataManager({
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Customers',
adaptor: new ODataV4Adaptor,
crossDomain: true
});
let filter: DropDownList = new DropDownList({
// set the remote data to dataSource property
dataSource: searchData,
// bind the Query instance to query property
query: new Query().select(['ContactName', 'CustomerID']).take(7),
// map the appropriate column
fields: { text: 'ContactName', value: 'CustomerID' },
// set placeholder to DropDownList input element
placeholder:"Select a name",
// sort the resulted items
sortOrder: 'Ascending',
// set true to allowFiltering for enable filtering supports
allowFiltering: true,
// bind the filtering event handler
filtering: (e: FilteringEventArgs) => {
// set limit as 4 to search result
let query: Query = new Query().select(['ContactName', 'CustomerID']).take(4);
query = (e.text !== '') ? query.where('ContactName', 'startswith', e.text, true) : query;
e.updateData(searchData, query);
}
});
filter.appendTo('#ddlelement');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 DropDownList</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="styles.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container' style="margin:0 auto; width:250px;">
<br>
<input type="text" id='ddlelement' />
</div>
</body>
</html>