简体   繁体   English

数据表+ YADCF + Select2-默认选择的数据

[英]Datatables + YADCF + Select2 - default selected data

In my project, based on Datatables+YADCF, works with more dropdowns and Select2 fields. 在我的项目中,基于Datatables + YADCF,可以使用更多下拉列表和Select2字段。 All data are loaded with Ajax requests. 所有数据都随Ajax请求一起加载。 Okay, and question: 好的,还有问题:

Is possible set default selected values in Select2 field after select value in dropdown? 在下拉列表中的选择值之后,是否可以在Select2字段中设置默认选择的值?

Or another question: Is possible autofill selected values in select2 field only with Ajax data? 或另一个问题:是否可能仅使用Ajax数据自动填充select2字段中的选定值?

(maybe: { key: 1, value: car, default: true } (也许: { key: 1, value: car, default: true }

UPDATE UPDATE

(Server is hosted on heroku (free plan - can be sleep after 30 min of inactivity). Server side is is not ideal, but for this example is probably okay.) (服务器托管在heroku上(免费计划-闲置30分钟后即可进入睡眠状态。)服务器端不是理想的选择,但对于此示例来说,还可以。)

Here is first example : 这是第一个例子

Basic using of Datatables + YADCF library. Datatables + YADCF库的基本用法。 Above of first column are names in dropdown element. 第一列上方是下拉元素中的名称。 In select2 above of second column are surnames. 在第二列上方的select2中为姓。 After selecting "name" in dropdown are filtered "surnames" in 2nd column. 在下拉列表中选择“名称”后,第二栏中将过滤“姓氏”。

https://jsfiddle.net/lukassliacky/fojp91zx/ https://jsfiddle.net/lukassliacky/fojp91zx/

2nd example: 第二个例子:

Surname "Winters" is prefilled after run example: 运行示例后,将预填写姓氏“ Winters”:

https://jsfiddle.net/lukassliacky/fojp91zx/6/ https://jsfiddle.net/lukassliacky/fojp91zx/6/

Okay, and question: 好的,还有问题:

In 2nd example are surnames prefilled after refresh with external API function: 在第二个示例中,是使用外部API函数刷新后预填的姓氏:

yadcf.exFilterColumn(oTable, [[1, ['Winters']]])

Please, is possible load this "prefilled surnames" from server after every request? 请在每次请求后是否可以从服务器加载此“预填姓氏”?

For example: I have countries in dropdown and i need load and prefill regions of selected country in select2 field. 例如:我在下拉列表中有国家/地区,并且我需要在select2字段中选择国家的装载和预填充区域。

Thank you for you answer. 谢谢您的回答。

You should use the yadcf.exFilterColumn method, see example 您应该使用yadcf.exFilterColumn方法,请参见示例

yadcf.exFilterColumn(oTable, [
  [0, ['Some Data 1', 'Some Data 2']]
]); 

for pre filtering multi select filter you should use array with values (or an array with single value) 对于预过滤多选过滤器,您应该使用带有值的数组(或带有单个值的数组)

read more in the docs 在文档中阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM