【问题标题】:Populate dropdown data in the customized Add function of Jqgrid from sql在 Jqgrid 的自定义 Add 函数中从 sql 填充下拉数据
【发布时间】:2015-03-24 20:31:24
【问题描述】:

我一直在尝试自定义 Jqgrid 中的默认添加表单以添加下拉列表并从数据库中填充其下拉数据,不知道该怎么做..

以下是我的一段代码,用于自定义名称列以提供下拉列表。

beforeShowForm:函数(表单){ $('#tr_Name').html('td class="CaptionTD">Name /td> td class="DataTD">  table> td> select role="select" id="resp" name="responsavel" size ="1" class="FormElement ui-widget-content ui-corner-all"> option role="option" value="1">ABC /option> option role="option" value="2">XYZ / option> option role="option" value="3">QWE /option> /select> /td>');

这里的选项值为 ABC,XYZ,QWE .. 但我不想硬编码它,而是希望它从 SQL 数据库中填充。

请求帮助。

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    在 colModel 中,您使用 dataurl 和 edittype:"select" 配置 editoptions

    colModel: [
    { name: "pers_genre_id", index: "pers_genre_id", width: 80, align: "right",
                    editable:true, edittype:"select", 
                    editoptions:{   
                            dataUrl:'ddl/ddl_genre.php',
                            }// end edit option
                },
    ]
    

    dataurl 是填充 ddl 内容的文件路径:

    <?php
        include("../dbconfig.php");
    
        $SQL = "SELECT * FROM t_genre";
    
        echo '<select>';
    
        $result = $dbh->prepare($SQL);
        $result->execute();
    
        while($row = $result->fetch()) {
    
             echo '<option value="'.$row['gen_id'].'">'.$row['gen_genre'].'</option>';
        }
    
        echo '</select>';
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 2011-11-09
      • 2014-12-25
      相关资源
      最近更新 更多