在jqgrid高级搜索中动态填充下拉选项的最佳方式 [英] best way to dynamically populate dropdown options in jqgrid advanced searching

查看:2270
本文介绍了在jqgrid高级搜索中动态填充下拉选项的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jqgrid高级搜索中动态填充下拉选项的最好方法是什么?



1)第一种方法:使用searchoptions的dataUrl >

缺点:当用户添加新标准并选择属性时,dataUrl被发布到服务器,当用户再次添加相同的条件时,dataUrl再次发布到服务器,两次。很奇怪。



优点:用户先前选择的值存在并且未清除。



2)第二种方法:使用dataInit 选项



缺点:添加新条件时,用户先前选择的值已被清除(无法接受,因为用户不方便,请参考网址:所选值在下拉列表中,在jqgrid高级搜索中添加新条件后清除



优点:当页面刷新时,数据已加载到页面中,



3)第三种方法是使用searchoptions



的value选项,只是在页面中硬编码。



任何人都可以分享有关问题的最佳实践。谢谢。

解决方案

我从第二个选项开始。我想你以错误的方式使用 dataInit dataInit 初始化控件的目标,例如convert < select> 到select2或设置jQuery UI Autocomplete或jQuery UI文本输入元素上的Datepicker。应该用值填充控件。在调用 dataInit 之前已经创建并填充了选择控件。



如果使用第一个选项,设置HTTP缓存头以防止多个请求 dataUrl



关于最后一个选项:可以设置<$ c例如,在 beforeProcessing 里面$ c> searchoptions.value 请参见答案这一个这一个


What's the best way to dynamically populate dropdown options in jqgrid advanced searching?

1) The first way: use "dataUrl" option of "searchoptions"

Disadvantage: when user add new criteria, and choose the attribute, dataUrl was posted to the server, when user add the same criteria again, dataUrl was posted to the server again, and with twice. very strange.

Advantage: the values user selected previously was there and not cleared.

2) The second way: use "dataInit" option of "searchoptions"

Disadvantage: the values user selected previously was cleared when adding new criteria(can not accepted, because it is not user-friendly, please refer url: the selected value was cleared in dropdown after add new criteria in jqgrid advanced searching)

Advantage: data was loaded into page when the page refreshed and only once.

3) the third way, use "value" option of "searchoptions"

but it's not dynamically, just hard-coded in page.

Could any one share the best practice about the issues. thanks.

解决方案

I start with the second option. I suppose that you use dataInit in the wrong way. The goal of dataInit to initialize the control, like convert <select> to select2 or set jQuery UI Autocomplete or jQuery UI Datepicker on text input element. One should not fill the control with values. The select control is already created and filled before calling of dataInit.

If one use the first option, one can set HTTP cache header to prevent multiple request to dataUrl.

About the last option: one can set searchoptions.value dynamically inside of beforeProcessing for example. See the answer, this one and this one.

这篇关于在jqgrid高级搜索中动态填充下拉选项的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆