1
如何使用格式化程序將dojo ComboBox
添加到我的DataGrid
?我從我一直在閱讀的想法認爲,我應該能夠添加一個dojo ComboBox
到我的DataGrid
與formatter
就像我用我的dojo CheckBox
(和我創建的另一個html頁面上的dojo Button
)完成的。我無法找到一個很好的例子。我正在使用Dojo 1.10.0。如何使用格式化程序將dojo組合框添加到我的DataGrid?
這裏是我現有的代碼不加載,因爲什麼是錯的我formatterCombobox
格式:
<!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>
您應該添加的這個解決方案是如何工作的描述。 :) – JasonMArcher 2014-10-15 21:43:30
該解決方案修復了3個問題,首先在第一個require語句中不需要ComboBox構造函數。其次,formatterComboBox函數嵌套在格式化函數內,現在它與格式化程序處於同一範圍內。最後,是formatterComboBox函數沒有被分配到佈局對象中相應的formatter:屬性。 – 2014-10-16 14:55:05