【发布时间】:2014-04-10 00:56:47
【问题描述】:
我正在使用一个 dojo 数据网格,它显示从服务器发送的坐标数据或来自添加到 ESRI 地图的引脚的坐标数据。
但是,当我单击单元格编辑文本框时,您可以更改值,但除非您正在编辑最后一行,否则更改不会保存。如果您编辑第 2 行中的文本框,然后单击同一列中最后一行的框,则第 2 行的值将放在最后一行中。
如果您以任何其他方式退出,第 2 行数据将恢复为其原始值。最后一行的行为完全符合我的要求,您可以编辑所有值并将它们保存(除非刷新页面)。如果添加了另一行,并且您尝试对其进行编辑,则该行将抛出一个
“Uncaught TypeError:Cannot read property 'get' of undefined” ObjectStore.js:8 上的错误。
我从 hellodgrid 示例中的代码开始 http://dojotoolkit.org/documentation/tutorials/1.9/working_grid/demo/ 使用“使用网格编辑数据”并编辑任意行中的列。
我还没有遇到过像我这样的问题,我真的很困惑,所以非常感谢任何帮助。
以下代码中的数据是我创建的对象数组。
function drawTable(data){
require([
"dojox/grid/DataGrid",
"dojox/grid/cells",
"dojox/grid/cells/dijit",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/date/locale",
"dojo/currency",
"dijit/form/DateTextBox",
"dojox/grid/_CheckBoxSelector",
"dojo/domReady!"
], function(DataGrid, cells, cellsDijit, Memory, ObjectStore, locale, currency,
DateTextBox, _CheckBoxSelector){
function formatDate(inDatum){
return locale.format(new Date(inDatum), this.constraint);
}
gridLayout = [
{
type: "dojox.grid._CheckBoxSelector",
defaultCell: { width: 8, editable: true, type: cells._Widget, styles: 'text-align: right;' }
},
//cells:
[
{ name: 'Number', field: 'order', editable: false /* Can't edit ID's of dojo/data items */ },
{ name: 'ID', field: 'uniqueID', width: 10, editable: false /* Can't edit ID's of dojo/data items */ },
{ name: 'Station ID', field: 'stationID', width: 15, editable: true },
/* No description for each station... at least not yet
{ name: 'Description', styles: 'text-align: center;', field: 'description', width: 10,
type: cells.ComboBox,
options: ["normal","note","important"]},*/
{ name: 'Road', field: 'road', width: 10, editable: true, styles: 'text-align: center;',
type: cells.CheckBox},
{ name: 'Route', field: 'route', width: 10, editable: true, styles: 'text-align: center;',
type: cells.CheckBox},
{ name: 'Count Type', width: 13, editable: true, field: 'countType',
styles: 'text-align: center;',
type: cells.Select,
options: ["new", "read", "replied"] },
{ name: 'Count Duration', field: 'countDuration', styles: '', width: 15, editable: true},
/*
May want to use this later
{ name: 'Date', field: 'col8', width: 10, editable: true,
widgetClass: DateTextBox,
formatter: formatDate,
constraint: {formatLength: 'long', selector: "date"}}, */
]
//{
];
objectStore = new Memory({data:data});
stationGridStore = new ObjectStore({objectStore: objectStore});
// create the grid.
grid = new DataGrid({
store: stationGridStore,
structure: gridLayout,
// rowSelector: '20px',
"class": "grid"
}, "grid");
grid.startup();
// grid.canSort=function(){return false;};
});
}
【问题讨论】:
标签: javascript datagrid dojo