0

編集フォームで選択ボックスの値を設定するのに苦労しています。たとえば、colModelを次のように設定しています。

colModel:[
         {name:'communication_id', key: true, index:'communication_id', width:30},            
         {name:'communication_type_id', index:'communication_type_id', width:30},
         {name:'communication_type_select',index:'communication_type_select',hidden:true,width:150, editable:true,edittype:'select',formatter:'select',editrules: {edithidden:true},
                                    formoptions:{label:'Communication Type'},
                                    editoptions:{dataUrl:"working_data_url",
                                        buildSelect: function(json){                                                
                                            var response = $.parseJSON(json);

                                            var s = '<select>';

                                            $.each(response.results,function(i,com){
                                                s += ('<option value="' + com.communication_type_id + '">'+ com.communication_type_desc + '</option>');
                                            });


                                            return s + "</select>";


                                        },dataInit: function(elem){
                                            alert(temp);
                                            //alert($('#com_table_communication_type_id').val());
                                            //$(elem).val($('#com_table_communication_type_id').val());
                                        }}},
         {name:'communication_send_dt', index:'communication_send_dt', width:150, sortable:true, sorttype: 'date',
                                    firstsortorder: 'desc', datefmt:'m/d/Y', editable:true},                                         

                            editoptions: {recreateForm:true},
                            rowNum:10,
                            width:'100%',
                            rowList:[10,20,30],
                            pager: '#com_pager',
                            sortname: 'communication_send_dt',
                            viewrecords: true,
                            sortorder: "desc",
                            loadonce:true,
                            caption: "Communication",
                            jsonReader: {
                                    repeatitems : false,
                                    root: "results"
                            },
                            height: '100%',
                            onSelectRow: function(communication_id){

                                var comtype = $(this).getRowData(communication_id);
                                var temp = comtype['communication_type_id'];

                            }
                    });

                    grid.jqGrid('navGrid','#com_pager',{edit:true,add:false,del:false});

編集ボタンをクリックすると、選択オプションが正しく読み込まれますが、どちらを選択するか問題があります。communication_type_idの値をcommunication_type_selectにロードしたいのですが、それを実現するためにさまざまなことを試みました。基本的に、communication_type_idのidが2の場合、編集フォームの読み込み時に編集フォームの選択ボックスも2に設定する必要があります。これについて何か助けはありますか?

アップデート1:beforeShowFormを使用することでほとんど機能するようになりましたが、今は奇妙なことに遭遇しています。beforeShowFormにアラートがあると、すべてが機能しますが、コメントアウトすると機能しません。助けてくれてありがとう@Oleg!

grid.jqGrid('navGrid','#com_pager',{edit:true,add:false,del:false},
                            {closeOnEscape:true, recreateForm:true,beforeShowForm: function(formid){  
                                //alert("com type id = "+comidvar + " response id = "+comrespvar + " com form type id = "+comfrmtypevar);
                                $("#communication_type_select", formid).attr("value",comidvar);
                                $("#form_response_select", formid).attr("value",comrespvar);
                                $("#form_type_select", formid).attr("value", comfrmtypevar);
                            }},
4

1 に答える 1

0

あなたが正しいことを理解したらajaxSelectOptions、jqGridのオプションをdataプロパティで使用する必要があります。を使用して返すことができる値のようcommunication_type_idに、追加のオプションを定義して、列から値を取得できます。詳細については、回答を参照してください。data$("#list").jqGrid('getGridParam', 'selrow')getCellcommunication_type_id

于 2012-06-28T21:34:53.017 に答える