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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{ name : & #039;IdTipoCollo', index:'IdTipoCollo', width:400, editable:true, hidden: true,
edittype : & #039;select',
editrules : { edithidden : true } ,
editoptions : {
dataUrl : & #039;lista_combobox/lista_tipi_colli_std.php',
postData : function ( rowid ) {
// Prendo i dati della spedizione
var cl = jQuery ( & #039;#gMain').jqGrid('getGridParam','selrow');
var dati_testata = jQuery ( & quot ; #gMain").jqGrid('getRowData', cl);
return {
action : & quot ; getState & quot ; ,
AutoSelect : & quot ; 0 & quot ;
}
} ,
dataInit : function ( element ) {
CaricaSelect2 ( true , element , & quot ; lista_combobox / lista_tipi_colli_std . php ? TipoOutput = 1 & amp ; AutoSelect = 0 & quot ; , i18next . t ( & #039;generic.search_dots'), [], 0, false, true);
} ,
dataEvents : [
{ type : & #039;change',
fn : function ( e ) {
// Editvalue e Keyvalue
var TestoSel = $ ( this ) . find ( & #039;option:selected').text();
var IdSel = $ ( this ) . children ( & quot ; : selected & quot ; ) . attr ( & quot ; value & quot ; ) ;
var ExtraData = $ ( this ) . select2 ( & #039;data')[0];
if ( ExtraData ) {
vLev = ExtraData . level ;
}
}
}
]
} ,
searchoptions : { clearSearch : false }
} ,
SELECT2 FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ ( IDCombo ) . select2 ( {
theme : & quot ; bootstrap4 & quot ; ,
allowClear : bAllowClear ,
dropdownAutoWidth : true ,
minimumInputLength : vMinLength ,
width : & #039;100%',
placeholder : vSearchText ,
ajax : {
url : vUrl ,
dataType : & #039;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 - & gt ; fetch ( ) ) {
$ return_arr [ ] = [
& #039;id' => $result['IdFiliale'],
& #039;text' => $result['Descrizione'],
& #039;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.