选择行并在文本框中显示它们

时间:2014-12-08 05:32:24

标签: dojo

在这里,我选择了不同的网格行,需要在文本框中显示所选行的值。我尝试如下所示但没有成功。

在这里,我选择了不同的网格行,需要在文本框中显示所选行的值。我尝试如下所示但没有成功。

<script>  
    require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
        function(lang, DataGrid, ItemFileWriteStore, dom)
        {

            /*set up data store*/
        var data = 
        {
                identifier: "id",
                items: []
        };

        var data_list = [
                      { col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
                      { col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
                      { col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
                    ];
           var rows = 60;

           for(var i = 0, l = data_list.length; i < rows; i++)
           {
            data.items.push(lang.mixin({ id: i+1 }, data_list[i%l]));
           }

        var store = new ItemFileWriteStore({data: data});

    /*set up layout*/
    var layout = [[
      {'name': 'Column 1', 'field': 'id', 'width': '100px'},
      {'name': 'Column 2', 'field': 'col2', 'width': '100px'},
      {'name': 'Column 3', 'field': 'col3', 'width': '200px'},
      {'name': 'Column 4', 'field': 'col4', 'width': '150px'}
    ]];

    /*create a new grid*/
    var grid = new DataGrid({
        id: 'grid',
        store: store,
        structure: layout,
        selectionMode: 'extended',
        rowSelector: '20px'});

        /*append the new grid to the div*/
        grid.placeAt("gridDiv");
        grid.startup();

        dojo.connect(grid, "onRowClick", function(e) {
        var dataItem = grid.selection.getSelected();
         onsole.dir(dataItem);
         //document.getElememtById("myText").value = dataItem
    });         
});

</script>

</head>
<body class="claro">
    <div id="gridDiv"></div>
    <input name="textbox1" id="myText" type="text" />
</body

1 个答案:

答案 0 :(得分:0)

getSelected()将为您提供一个表示所选行的ItemFileWriteStore对象数组。要在事件处理程序中获取第一个选定行的字段值: -

var selectedRowsArray = grid.selection.getSelected();
var firstSelectedRow_field_value = selectedRowsArray[0].field_name[0];

textBox.set("value", firstSelectedRow_field_value);