ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.04k stars 1.29k forks source link

👑 [需求] 关于 ProFormSelect 的搜索模式 #2527

Closed jiyingzhi closed 1 year ago

jiyingzhi commented 3 years ago

🥰 需求描述

现在 ProFormSelect 的搜索模式,当使用 request 配置搜索选项时,每次输入一个字符,都会调用一个接口。个人感觉不是很合理。 想了一下,Select 的搜索模式大致可以分为两种,第一种是前端搜索,一次性从服务端获取选项,以后的输入都不会触发接口调用,而只是前端过滤,这种适用于搜索项比较少的情况。第二种是搜索项非常多的情况下,这时候一次性请求太多数据会对服务端造成性能影响,所以初始不会请求数据,只有在用户每次输入时,将输入的关键字传给后端,然后返回筛选后的数据,也就是后端搜索。现在的 ProFormSelect 好像是根据 keywords 调接口后又走了一遍前端筛选。相关 issue:#2326。

🧐 解决方案

ProFormSelect是前端搜索,只在第一次请求接口,后续输入只是在前端做过滤,ProFormSelect.SearchSelect 是后端搜索,每次输入会把 keywords 传给后端,不做前端搜索,并且支持单选。

chenshuai2144 commented 3 years ago

来个pr吧。有 request 的时候不要使用本地筛选

github-actions[bot] commented 3 years ago

Hello @jiyingzhi. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @jiyingzhi,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请务必提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

jiyingzhi commented 3 years ago

可不可以提供一个只在前端做搜索的功能

chenshuai2144 commented 3 years ago

request 不在的时候就是只在前端搜索吧

zhangfangkai commented 3 years ago

这个问题解决了么,现在是只要配置了request,每次输入都会请求后端接口,然后前端过滤,很烦人。能否只第一次请求后端,之后输入就用前端搜索呢?

zhangfangkai commented 3 years ago

🥰 需求描述

现在 ProFormSelect 的搜索模式,当使用 request 配置搜索选项时,每次输入一个字符,都会调用一个接口。个人感觉不是很合理。 想了一下,Select 的搜索模式大致可以分为两种,第一种是前端搜索,一次性从服务端获取选项,以后的输入都不会触发接口调用,而只是前端过滤,这种适用于搜索项比较少的情况。第二种是搜索项非常多的情况下,这时候一次性请求太多数据会对服务端造成性能影响,所以初始不会请求数据,只有在用户每次输入时,将输入的关键字传给后端,然后返回筛选后的数据,也就是后端搜索。现在的 ProFormSelect 好像是根据 keywords 调接口后又走了一遍前端筛选。相关 issue:#2326。

🧐 解决方案

ProFormSelect是前端搜索,只在第一次请求接口,后续输入只是在前端做过滤,ProFormSelect.SearchSelect 是后端搜索,每次输入会把 keywords 传给后端,不做前端搜索,并且支持单选。

很合理,不知道有没有完成呢

alantoa commented 2 years ago

+1

xiaofuliang commented 2 years ago

+1

taoliujun commented 2 years ago

请问有 mr了吗

cuijiudai commented 1 year ago

+1

hsbtr commented 1 year ago

这个问题解决了么,现在是只要配置了request,每次输入都会请求后端接口,然后前端过滤,很烦人。能否只第一次请求后端,之后输入就用前端搜索呢?

这个功能似乎上线无望

cdz620 commented 1 year ago

之前好像确实有这个问题,目前使用发现没这个问题,大伙升级试试

hsbtr commented 1 year ago

ProFormSelect直接使用还是会有这个问题,看了源码才发现必须在fieldProps中传入fetchDataOnSearch: false,才可以避免筛选重新请求

cuijiudai commented 1 year ago

ProFormSelect直接使用还是会有这个问题,看了源码才发现必须在fieldProps中传入fetchDataOnSearch: false,才可以避免筛选重新请求

没用啊

Warning: React does not recognize the fetchDataOnSearch prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase fetchdataonsearch instead. If you accidentally passed it from a parent component, remove it from the DOM element.

hsbtr commented 1 year ago

ProFormSelect直接使用还是会有这个问题,看了源码才发现必须在fieldProps中传入fetchDataOnSearch: false,才可以避免筛选重新请求

没用啊

Warning: React does not recognize the fetchDataOnSearch prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase fetchdataonsearch instead. If you accidentally passed it from a parent component, remove it from the DOM element.

我的pro-form是1.70x

cdle commented 1 year ago

原来你们这群人把这功能搞没了,我还想要后端搜索呢

zwmmm commented 1 year ago

原来你们这群人把这功能搞没了,我还想要后端搜索呢

解决了么,我服了

hsbtr commented 1 year ago

原来你们这群人把这功能搞没了,我还想要后端搜索呢

这个功能似乎是1.70.x以后的版本才上的,并且没有删除原有功能,只是在额外在fieldProps中添加了一个属性fetchDataOnSearch 用来关闭;默认一直都是开启请求的

GoToBoy commented 8 months ago

ProFormSelect直接使用还是会有这个问题,看了源码才发现必须在fieldProps中传入fetchDataOnSearch: false,才可以避免筛选重新请求

有用

loveCHN commented 2 weeks ago

fetchDataOnSearch为啥文档里没写?坑死啦!