我正在使用一個dojo數據網格,它正在顯示數據或者是從服務器發送的座標數據,或者是來自添加到ESRI地圖的引腳的座標數據。只能編輯Dojo DataGrid的最後一行
但是,當我單擊一個單元格來編輯文本框顯示並且您可以更改該值時,除非您正在編輯最後一行,否則更改不會保存。如果編輯第2行中的文本框,然後單擊最後一行的同一列中的框,則第2行的值將放入最後一行。
如果退出任何其他方式,第2行數據將恢復爲其原始值。最後一行的行爲正是我想要的,你可以編輯所有的值並保存(除非頁面被刷新)。如果添加了另一行,並且您嘗試對其進行編輯,則該行將拋出一個「未捕獲的類型錯誤:無法讀取ObjectStore.js上的未定義的」錯誤「屬性:'8':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;};
});
}
哇,太感謝你了!我不知道它假定了id屬性。如果只有每個修補程序都那麼簡單... – farnett