Skip to main content

addMultiSearch(onInputChange, keys)

Use this method in case you want to provide a search endpoint that returns results for multiple record types. CommandBar will ensure that your endpoint is called only once per debounced input change.

If you have separate custom search functions for each record type, you should instead use addRecords to make them known to CommandBar.

Example

// Function invoking multi search API endpoint
const onInputChange = () => {
const onSearchGrains = (query) => {
return fetch(`https://yourapi.com/search?=${query}`).then((response) =>
response.json()
);
};
const vehicles = ["Sedan", "SUV", "MUV", "Coupe"];
return (
new Promise() <
any >
((resolve) => {
setTimeout(() => {
resolve({
grains: onSearchGrains(),
vehicles: vehicles,
});
}, 10);
})
);
};

// Add two different records
window.CommandBar.addRecords("grains", []);
window.CommandBar.addRecords("vehicles", []);

// Add a search endpoint
window.CommandBar.addMultiSearch(onInputChange, ["grains", "vehicles"]);

Method parameters

onInputChange Required

function | async function

This custom search function should take as its first argument a string query and return an object that holds results for each key in keys, such as { key1: result[], key: result[]}. The function will be called only once per input change. Results from the custom search function should be filtered; they will not be filtered by CommandBar. This means that the search results will be identical to those returned by the function.

keys Required

string[]

Specifies which record types are supported by the specified search endpoint.