I'm using select2 with jqGrid. For "select" elemets I do folowing:
{label:"Teacher",name:"teacher",index:"teacher",editable:true,edittype:"select",
editoptions:{
dataUrl:"../ajax/selects/select_teachers.php",
width:"400px",
dataInit: function (elem) {
$(elem).select2({
placeholder: "Choose teacher",
allowClear: true,
language:"ru"
});
setTimeout(function() {
$(".select2-container").width("300");
},
0);
},
},
But when open editForm select in in default mode. How to get select2 to select right value in editform ?
=======
Additional info. I have jqGrid. One of the column in the colModel looks like this:
{label:"Jobplace",name:"job_place",index:"job_place",editable:true,edittype:"select",
editoptions:{
dataUrl:"../ajax/selects/select_spr_companies.php",
dataInit: function (elem) {
$(elem).select2({
placeholder: "Choose job place",
allowClear: true,
});
setTimeout(function() {
$(".select2-container").width("300");
},
0);
}
},hidden:false,align:"center",sortable:true,search:true,searchoptions:{sopt:["cn"]},width:50},
So, select2 element showing "Choose job place". result editformThere is now selected vaule. But I try to edit row and this is row already have selected element. Why select2 not showing right selected value when I try do edit row? As Oleg wrote below I try to change my colModel like this:
{label:"Job place",name:"job_place",index:"job_place",editable:true,edittype:"select",
editoptions:{
dataUrl:"../ajax/selects/select_spr_companies.php",
selectFilled: function (elem) {
$(elem).select2({
placeholder: "Choose job place",
allowClear: true,
});
setTimeout(function() {
$(".select2-container").width("300");
},
0);
}
},hidden:false,align:"center",sortable:true,search:true,searchoptions:{sopt:["cn"]},width:50},
But I get folowing on editform: select2 completely stop to work as expected.