2014-09-10 3 views
1

포맷터를 사용하여 DataGrid에 dojo ComboBox을 어떻게 추가합니까? Dojo를 추가 할 수 있어야한다고 생각했는데 ComboBox은 내 DataGridformatter과 같습니다. 내 도장을 완료했습니다. CheckBox (내가 만든 다른 html 페이지의 Button). 나는 이것의 좋은 모범을 발견 할 수 없다. Dojo 1.10.0을 사용 중입니다.포맷터를 사용하여 DataGrid에 dojo ComboBox를 어떻게 추가합니까?

<!DOCTYPE html> 
<html > 
<head> 
<title>Test Widget</title> 
    <link rel="stylesheet" type="text/css" href="dojo-release-1.10.0/dijit/themes/claro/claro.css" /> 
    <link rel="stylesheet" type="text/css" href="css/dojomod.css" /> 
    <link rel="stylesheet" href="dojo-release-1.10.0/dojo/resources/dojo.css" /> 
    <link rel="stylesheet" href="dojo-release-1.10.0/dojox/grid/resources/claroGrid.css" /> 
    <script>dojoConfig = {async: true, parseOnLoad: false}</script> 
    <script src="dojo-release-1.10.0/dojo/dojo.js"></script> 

    <script> 
require(['dojox/grid/DataGrid', 'dojo/data/ItemFileReadStore', 'dijit/form/CheckBox', 'dojo/domReady!'], 
    function(DataGrid, ItemFileReadStore, CheckBox){ 
     function formatter(){ 
      var w = new CheckBox({ 
       label: "Use Input", 
       onClick: function() { 
        alert("CheckBox - Checked! (or unchecked!)"); 
       } 
      }); 
      w._destroyOnRemove=true; 
      return w; 

     function formatterCombobox(){ 
      var combobox = new ComboBox({ 
       label: "Combo", 
       onClick: function() { 
        alert("CheckBox - Checked! (or unchecked!)"); 
       } 
      }); 
      combobox._destroyOnRemove=true; 
      return combobox; 
     } 

     } 
     var layout = [ 
      {name: 'Feed', field: 'feed'}, 
      {name: 'Mission', field: 'mission', width: 6.5, 
       styles: 'text-align: center; height: 21px;'}, 
      {name: 'Mission Override', field: 'missionoverride', width: 6.5, 
       formatter: formatter, /*Custom format, add a CheckBox. */ 
       styles: 'text-align: center;' 
      }, 
      {name: 'OpMode', field: 'opmode', width: 6.5, 
       styles: 'text-align: center; height: 21px;'}, 
      {name: 'OpMode Override', field: 'opmodeoverride', width: 6.5, 
       formatter: formatter, /*Custom format, add a CheckBox. */ 
       styles: 'text-align: center; height: 21px;' 
      }, 
      {name: 'Platform', field: 'platform', width: 6.5, 
       styles: 'text-align: center; height: 21px;'}, 
      {name: 'Tail Number', field: 'tailnumber', width: 6.5, 
       styles: 'text-align: center; height: 21px;' 
      }, 
      {name: 'Producer Org', field: 'producerorg', width: 6.5, 
       styles: 'text-align: center; height: 21px;' 
      }, 
     ]; 
     var store = new ItemFileReadStore({ 
      data: { 
       identifier: "feed", 
       items: [ 
        {feed: '1. feed1', mission: 'mission1', override: '', mode: '', override: '', platform: '', number: '236', org: 'SA'}, 
        {feed: '2. feed2', mission: 'mission2', override: '', mode: '', override: '', platform: '', number: '980', org: 'SA'}, 
        {feed: '3. feed3', mission: 'mission3', override: '', mode: '', override: '', platform: '', number: '731', org: 'SA'}, 
        {feed: '4. feed4', mission: 'mission4', override: '', mode: '', override: '', platform: '', number: '415', org: 'SA'}, 
        {feed: '5. feed5', mission: 'mission5', override: '', mode: '', override: '', platform: '', number: '899', org: 'SA'}, 
       ] 
      } 
     }); 

     require([ 
       "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!" 
      ], function(Memory, ComboBox){ 
       var stateStore = new Memory({ 
        data: [ 
         {name:"Alabama", id:"AL"}, 
         {name:"Alaska", id:"AK"}, 
         {name:"American Samoa", id:"AS"}, 
         {name:"Arizona", id:"AZ"}, 
         {name:"Arkansas", id:"AR"}, 
         {name:"Armed Forces Europe", id:"AE"}, 
         {name:"Armed Forces Pacific", id:"AP"}, 
         {name:"Armed Forces the Americas", id:"AA"}, 
         {name:"California", id:"CA"}, 
         {name:"Colorado", id:"CO"}, 
         {name:"Connecticut", id:"CT"}, 
         {name:"Delaware", id:"DE"} 
        ] 
       }); 

       var comboBox = new ComboBox({ 
        id: "stateSelect", 
        name: "state", 
        value: "California", 
        store: stateStore, 
        searchAttr: "name" 
       }, "stateSelect").startup(); 
      }); 

     var grid = new DataGrid({ 
      id: 'grid', 
      store: store, 
      structure: layout, 
      autoWidth: true, 
      autoHeight: true 
     }); 
     grid.placeAt('gridContainer'); 
     grid.startup(); 
    }); 
    </script> 
</head> 
<body class="claro"> 
    <div id="gridContainer" style="width: 100%; height: 200px;"></div> 
</body> 
</html> 

답변

2
<script> 

     require(['dojox/grid/DataGrid', 'dojo/data/ItemFileReadStore', 'dijit/form/CheckBox', "dijit/form/ComboBox", 'dojo/domReady!'], 
       function (DataGrid, ItemFileReadStore, CheckBox, ComboBox) { 
        function formatter() { 
         var w = new CheckBox({ 
          label: "Use Input", 
          onClick: function() { 
           alert("CheckBox - Checked! (or unchecked!)"); 
          } 
         }); 
         w._destroyOnRemove = true; 
         return w; 

        } 

        function formatterCombobox() { 
         var combobox = new ComboBox({ 
          label: "Combo", 
          onClick: function() { 
           alert("CheckBox - Checked! (or unchecked!)"); 
          } 
         }); 
         combobox._destroyOnRemove = true; 
         return combobox; 
        } 

        var layout = [ 
         {name: 'Feed', field: 'feed'}, 
         {name: 'Mission', field: 'mission', width: 6.5, 
          styles: 'text-align: center; height: 21px;'}, 
         {name: 'Mission Override', field: 'missionoverride', width: 6.5, 
          formatter: formatter, /*Custom format, add a CheckBox. */ 
          styles: 'text-align: center;' 
         }, 
         {name: 'OpMode', field: 'opmode', width: 6.5, 
          styles: 'text-align: center; height: 21px;'}, 
         {name: 'OpMode Override', field: 'opmodeoverride', width: 6.5, 
          formatter: formatter, /*Custom format, add a CheckBox. */ 
          styles: 'text-align: center; height: 21px;' 
         }, 
         {name: 'Platform', field: 'platform', width: 6.5, 
          formatter: formatterCombobox, 
          styles: 'text-align: center; height: 21px;'}, 
         {name: 'Tail Number', field: 'tailnumber', width: 6.5, 
          styles: 'text-align: center; height: 21px;' 
         }, 
         {name: 'Producer Org', field: 'producerorg', width: 6.5, 
          formatter: formatterCombobox, 
          styles: 'text-align: center; height: 21px;' 
         }, 
        ]; 
        var store = new ItemFileReadStore({ 
         data: { 
          identifier: "feed", 
          items: [ 
           {feed: '1. feed1', mission: 'mission1', override: '', mode: '', override: '', platform: '', number: '236', org: 'SA'}, 
           {feed: '2. feed2', mission: 'mission2', override: '', mode: '', override: '', platform: '', number: '980', org: 'SA'}, 
           {feed: '3. feed3', mission: 'mission3', override: '', mode: '', override: '', platform: '', number: '731', org: 'SA'}, 
           {feed: '4. feed4', mission: 'mission4', override: '', mode: '', override: '', platform: '', number: '415', org: 'SA'}, 
           {feed: '5. feed5', mission: 'mission5', override: '', mode: '', override: '', platform: '', number: '899', org: 'SA'}, 
          ] 
         } 
        }); 

        require([ 
         "dojo/store/Memory", "dijit/form/ComboBox", "dojo/domReady!" 
        ], function (Memory, ComboBox) { 
         var stateStore = new Memory({ 
          data: [ 
           {name: "Alabama", id: "AL"}, 
           {name: "Alaska", id: "AK"}, 
           {name: "American Samoa", id: "AS"}, 
           {name: "Arizona", id: "AZ"}, 
           {name: "Arkansas", id: "AR"}, 
           {name: "Armed Forces Europe", id: "AE"}, 
           {name: "Armed Forces Pacific", id: "AP"}, 
           {name: "Armed Forces the Americas", id: "AA"}, 
           {name: "California", id: "CA"}, 
           {name: "Colorado", id: "CO"}, 
           {name: "Connecticut", id: "CT"}, 
           {name: "Delaware", id: "DE"} 
          ] 
         }); 

         var comboBox = new ComboBox({ 
          id: "stateSelect", 
          name: "state", 
          value: "California", 
          store: stateStore, 
          searchAttr: "name" 
         }, "stateSelect").startup(); 
        }); 

        var grid = new DataGrid({ 
         id: 'grid', 
         store: store, 
         structure: layout, 
         autoWidth: true, 
         autoHeight: true 
        }); 
        grid.placeAt('gridContainer'); 
        grid.startup(); 
       }); 
    </script> 
+2

당신은이 솔루션의 작동 방법에 대한 설명을 추가해야합니다 :

여기에 뭔가가 내 formatterCombobox 포맷 문제 때문에로드되지 않는 기존 코드입니다. :) – JasonMArcher

+1

솔루션은 첫 번째 요구 문에 ComboBox 생성자가 필요하지 않은 3 가지 문제를 해결합니다. 두 번째로 formatterComboBox 함수는 formatter 함수 내에 중첩되어 이제는 formatter와 동일한 범위에 있습니다. 마지막으로, formatterComboBox 함수가 layout 객체의 적절한 formatter : property에 할당되지 않았습니다. –