jqGrid, how to populate select list from query

前端 未结 7 1513
盖世英雄少女心
盖世英雄少女心 2021-01-02 20:02

I got a basic jqGrid working in my coldfusion project. One of my fields in jqGrid is a combo box. Currently the editoption values are hard coded just like below.

<         


        
7条回答
  •  感动是毒
    2021-01-02 20:31

    I know this is an old question, but it I've find the same problem.
    I solve this by combination of dataUrl and ajaxSelectOptions.

    colModel:[
        //class_id
        $.extend(true,
        {
            name:'class_id'
            ,index:'class_id'
            ,edittype:'select'
            ,formatter:'select'
            ,editoptions: { dataUrl:"db.php?ajaxOp=getClassesOptions" } //to send dynamic parameter, combine with ajaxSelectOptions
        }
        ,{}
        )
    

    Note that dataUrl string ARE static, means you cannot send different parameters each time add/edit occurs. Below code WILL NOT WORK !

    ,editoptions: { dataUrl:"db.php?ajaxOp=getClassesOptions" + "&id="+selected_id } 
    

    To send parameters such id, you can use ajaxSelectOptions .

    ajaxSelectOptions:      //use this for combination with dataUrl for formatter:select
    {       
        data: {
          id: function () {
              return selected_id;
          }
        }
    },     
    

    The function which return selected_id will be executed each time the add/edit occurs. Hope this helps !

提交回复
热议问题