有人能帮助我如何在DataGrid(dojox/grid)单元格中为列中的每个单元格分别编程地设置组合框吗?
结构参数:cellType完成了它的工作,但是列中的所有单元格都继承定义的类型。
使用格式化程序函数,我们可以返回Combobox对象,但它的行为与使用cellType插入的Combobox不同。
我也在考虑onStartEdit函数,但我不知道如何实现它。
我想实现的是,如果在单元格是值,这是文本,然后我想显示组合框的所有可能性。在情况下,值作为一个数字比我不想显示组合框在所有。
样本代码:(Dojo版本1.9.11)
require([
"dojo/data/ItemFileReadStore",
"dojo/store/Memory",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore",
"dojo/dom",
"dojo/dom-construct",
"dijit/form/ComboBox",
"dojox/grid/cells/dijit",
"dojo/dom-style",
"dojo/domReady!"],
function(ItemFileReadStore, Memory, DataGrid, ObjectStore, dom, domConstruct, ComboBox, dijit, domStyle){
var dataArray = [];
var dataMemory = new Memory({data:dataArray});
var gridStruc = [];
gridStruc.push({name: 'Name', field: 'col1', width: '100px', editable: false});
gridStruc.push({name: 'Type', field: 'col2', width: '100px', editable: false});
gridStruc.push({name: 'Value (cellType)', field: 'col3', width: '100px', editable: true, cellType: 'dojox.grid.cells.ComboBox', options: ["Test1","Test2"]});
gridStruc.push({name: 'Value (formatter)', field: 'col4', width: '100px', editable: true, formatter: formatterCb});
var columnObj0 = {};
columnObj0["col1"] = "Voltage";
columnObj0["col2"] = "Number";
columnObj0["col3"] = "5";
columnObj0["col4"] = "5";
dataMemory.put(columnObj0);
var columnObj1 = {};
columnObj1["col1"] = "Type";
columnObj1["col2"] = "Text";
columnObj1["col3"] = "THT";
columnObj1["col4"] = "THT";
dataMemory.put(columnObj1);
var columnObj2 = {};
columnObj2["col1"] = "Num. Reflow";
columnObj2["col2"] = "Number";
columnObj2["col3"] = "3";
columnObj2["col4"] = "3";
dataMemory.put(columnObj2);
var columnObj3 = {};
columnObj3["col1"] = "Series";
columnObj3["col2"] = "Text";
columnObj3["col3"] = "CBK34";
columnObj3["col4"] = "CBK34";
dataMemory.put(columnObj3);
var dataStore = new ObjectStore({ objectStore: dataMemory});
grid = new DataGrid({
store: dataStore,
structure: gridStruc
},"gridDiv");
grid.startup();
function formatterCb(value, rowIndex, rowItem)
{
var storeItems=[];
storeItems.push({name: "Test1", value: "test1"});
storeItems.push({name: "Test2", value: "test2"});
var store = new ItemFileReadStore({data: {identifier:"name", items: storeItems}});
var w = new ComboBox({
label: "Use Input",
store: store,
value: value
});
w._destroyOnRemove = true;
return w;
}
});
1条答案
按热度按时间8aqjt8rx1#
我认为定义格式化器函数可能会有帮助。请看文档中的这个例子
在您的情况下,它将在这里:
我不知道为什么要使用array.push,但在本例中这并不重要。
也检查this tutorial,有一个例子,如何把小部件在单元格。它可能会有帮助。