reactjs - Start search on Enter using React material-table
问题描述
I'm new to using React and material-table and am trying to sort out how to initiate search after the user presses Enter. I've been able to find the debounceInterval
option, but the API I am using to search remote data currently does not return partial matches so I'd like the user to press "Enter" when they want the search to start.
Using monitorEvents($0)
I can see that there is a keydown
Event on the element input.MuiInputBase-input.MuiInput-input.MuiInputBase-inputAdornedStart.MuiInputBase-inputAdornedEnd
but I'm not sure how to add an event listener here or is there is an option to specify which event.target.value
to use to start the search. The material-table Search code is here: https://github.com/mbrn/material-table/blob/master/src/components/m-table-toolbar.js
Any help would be greatly appreciated.
解决方案
例子:
<TextField
onKeyPress={(ev) => {
console.log(`Pressed keyCode ${ev.key}`);
if (ev.key === 'Enter') {
// Do code here
ev.preventDefault();
}
}}
/>
推荐阅读
- git - 如何将版本化文件夹更改为 git 版本和分支?
- java - 使用 Node.js 打印 RTF/HTML 文件
- c++ - 在 Qt/c++ 项目中使用 MVC 时,如何通知单独窗口中的视图?
- c++ - OpenCV - FAST+BRIEF:如何使用 DrawMatchesFlags::DRAW_RICH_KEYPOINTS 绘制关键点?
- asp.net-mvc - HTTP Get 上查询字符串中的可读数据
- java - 在用户计算机上的 sqlite DB 上使用 jdbc 设置相对路径
- functional-programming - Prolog 创建字典
- database - Kubernetes:如何管理具有多个副本的数据?
- java - 如何将以下 Java 代码转换为 Node.js?
- django - Django/Graphene/Apollo/django-webpack-loader/Vue:CORS/CSRF 不能一起工作?