DHTMLX网格:使用下拉菜单填充单元格

2 html javascript c# jquery dhtmlx

我有2列dhtmlx grid table.我想dropdown menu为每个单元格填充第二列.

我生成xml documentC#

generated xml文件在C#:

<rows>

  <head>
    <column type="ed" width="205" sort="str">Product</column>
    <column type="co" width="205" sort="na" id="last">Class</column>
  </head>

 <row id="1">
   <cell>Product_name_1</cell>
   <cell>
    <select>
      <option id="1" value="1">first_option</option>
      <option id="2" value="2">second_option</option>
    </select>
   </cell>
 </row>

 <row id="2">
   <cell>Product_name_2</cell>
   <cell>
    <select>
      <option id="3" value="4">first_option</option>
      <option id="4" value="4">second_option</option>
    </select>
   </cell>
 </row>

</rows>
Run Code Online (Sandbox Code Playgroud)

Html并且Javascript code:

<body>
<div id="mygrid_container" style="width:1026px;height:500px"></div>
<script>
    var mygrid;
    $(document).ready(function () { 
        $.ajax({
            url: "/Admin/XMLForProducts",
            dataType: "json",
            type: "GET",
            data: {},
            success: function (result) {
                mygrid = new dhtmlXGridObject('mygrid_container');
                mygrid.init();
                mygrid.parse(result, "xml");
            }
        });
    });
</script>
</body>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我只是在第一列填充值(Product_name_1Product_name_2),我没有得到第二列的每个单元格的下拉菜单,我不知道如何解决这个问题.

小智 5

  1. 您需要使用某种类型来转义xml中的空格字符.例如,

代替:

    <cell>
        <select>
          <option id="3" value="4">first_option</option>
          <option id="4" value="4">second_option</option>
        </select>
       </cell>
Run Code Online (Sandbox Code Playgroud)

你需要:

<cell><![CDATA[<select><option id="3" value="4">first_option</option><option id="4" value="4">second_option</option></select>]]></cell>
Run Code Online (Sandbox Code Playgroud)

以下是关于在xml中处理特殊字符的教程:http://docs.dhtmlx.com/doku.php? id =其他:特殊字符_字符 _in_xml

  1. 此外,我们不建议在您的网格中使用html输入.您可以尝试使用"combo"exCell.

在这里你可以找到一个现成的例子:

http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/13_interaction_other_components/01_pro_combo.html

和教程:http://docs.dhtmlx.com/doku.php?id = ddtmlxgrid : how_to_use_new_excell_combo