The search plugin provides an easy interface to search data across Handsontable.
In order to enable search mechanism, Options#search option must be set to true.
Example
// as boolean
search: true
// as a object with one or more options
search: {
callback: myNewCallbackFunction,
queryMethod: myNewQueryMethod,
searchResultClass: 'customClass'
}
// Access to search plugin instance:
const searchPlugin = hot.getPlugin('search');
// Set callback programmatically:
searchPlugin.setCallback(myNewCallbackFunction);
// Set query method programmatically:
searchPlugin.setQueryMethod(myNewQueryMethod);
// Set search result cells class programmatically:
searchPlugin.setSearchResultClass(customClass);
Methods
-
destroy()
-
Destroys the plugin instance.
-
disablePlugin()
-
Disables the plugin functionality for this Handsontable instance.
-
enablePlugin()
-
Enables the plugin functionality for this Handsontable instance.
-
getCallback(){function}
-
Gets the callback function.
Returns: {function} Return the callback function.
-
getQueryMethod(){function}
-
Gets the query method function.
Returns: {function} Return the query method.
-
getSearchResultClass(){String}
-
Gets search result cells class name.
Returns: {String} Return the cell class name.
-
isEnabled(){Boolean}
-
Checks if the plugin is enabled in the handsontable settings. This method is executed in
Hooks#beforeInit
hook and if it returnstruethan theAutoRowSize#enablePluginmethod is called.Returns: {Boolean}
-
query(queryStr, callback, queryMethod){Array.<Object>}
-
Makes the query.
Parameters:
Name Type Description queryStrString Value to be search.
callbackfunction optional Callback function performed on cells with values which matches to the searched query.
queryMethodfunction optional Query function responsible for determining whether a query matches the value stored in a cell.
Returns: {Array.<Object>} Return an array of objects with
row,col,dataproperties or empty array. -
setCallback(newCallback)
-
Sets the callback function. This function will be called during querying for each cell.
Parameters:
Name Type Description newCallbackfunction -
setQueryMethod(newQueryMethod)
-
Sets the query method function. The function is responsible for determining whether a query matches the value stored in a cell.
Parameters:
Name Type Description newQueryMethodfunction -
setSearchResultClass(newElementClass)
-
Sets search result cells class name. This class name will be added to each cell that belongs to the searched query.
Parameters:
Name Type Description newElementClassString -
updatePlugin()
-
Updates the plugin state. This method is executed when
Core#updateSettingsis invoked.