How do I change selected value of select2 dropdown with JqGrid?

后端 未结 16 987
遥遥无期
遥遥无期 2020-11-27 10:27

I\'m using Oleg\'s select2 demo, but I am wondering whether it would be possible to change the currently selected value in the dropdown menu.

For example, if the fou

16条回答
  •  悲&欢浪女
    2020-11-27 10:58

    Looking at the select2 docs you use the below to get/set the value.

    $("#select").select2("val"); //get the value
    $("#select").select2("val", "CA"); //set the value
    

    @PanPipes has pointed out that this has changed for 4.x (go toss him an upvote below). val is now called directly

    $("#select").val("CA");

    So within the loadComplete of the jqGrid you can get whatever value you are looking for then set the selectbox value.

    Notice from the docs

    Notice that in order to use this method you must define the initSelection function in the options so Select2 knows how to transform the id of the object you pass in val() to the full object it needs to render selection. If you are attaching to a select element this function is already provided for you.

提交回复
热议问题