Hello,
I tried to put it on jsfiddle but it’s not working. I don’t know how to make that kind of ajax call.
I will try to write the code here hoping you can simulate it.
MAIN JAVASCRIPT:
{name:'IdTipoCollo', index:'IdTipoCollo', width:400, editable:true, hidden: true,
edittype:'select',
editrules:{edithidden: true},
editoptions:{
dataUrl:'lista_combobox/lista_tipi_colli_std.php',
postData: function (rowid) {
// Prendo i dati della spedizione
var cl = jQuery('#gMain').jqGrid('getGridParam','selrow');
var dati_testata = jQuery("#gMain").jqGrid('getRowData', cl);
return {
action: "getState",
AutoSelect: "0"
}
},
dataInit: function(element) {
CaricaSelect2(true, element, "lista_combobox/lista_tipi_colli_std.php?TipoOutput=1&AutoSelect=0", i18next.t('generic.search_dots'), [], 0, false, true);
},
dataEvents: [
{type: 'change',
fn: function (e) {
// Editvalue e Keyvalue
var TestoSel = $(this).find('option:selected').text();
var IdSel = $(this).children(":selected").attr("value");
var ExtraData = $(this).select2('data')[0];
if(ExtraData){
vLev = ExtraData.level;
}
}
}
]
},
searchoptions:{clearSearch:false}
},
SELECT2 FUNCTION
$(IDCombo).select2({
theme: "bootstrap4",
allowClear: bAllowClear,
dropdownAutoWidth : true,
minimumInputLength: vMinLength,
width: '100%',
placeholder: vSearchText,
ajax: {
url: vUrl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
page: params.page || 1,
doPages: bDoPages
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data,
pagination: {
more: false
}
};
},
cache: true
}
});
PHP:
while($result = $stmt->fetch()){
$return_arr[] = [
'id' => $result['IdFiliale'],
'text' => $result['Descrizione'],
'level' => $result['level']
];
$i++;
};
echo json_encode($return_arr);
So as you can see PHP returns ID, text, and level.
When outside of jqgrid I can do
var ExtraData = $(this).select2(‘data’)[0];
if(ExtraData){
vLev = ExtraData.level;
}
But When inside jqgrid it looks like it returns just id and text but it’s missing all the extra values.