我正在尝试向Dojo Datagrid添加删除按钮,我目前有以下javascript:
function createGrid() {
gridTmp = new dojox.grid.DataGrid({
store: jsonStore,
structure: [
{name: "Report No", field:"inc_number"},
{name: "Incident Date", field: "IncidentDate"},
{name: "Report Date", field: "reportDate"},
{name: "Location", field: "location"},
{name: "Delete", field: "inc_number", formatter: getDelete}
],
noDataMessage: 'No results returned'
}, "grids");
return gridTmp;
}
dojo.addOnLoad(function() {
grid = createGrid();
grid.startup();
});
function getDelete(item) {
return "<button onclick=\"location.href='/report?command=delete&reportNo="
+ store.getIdentity(item) + "'\">Delete</button>";
}
Run Code Online (Sandbox Code Playgroud)
每当我加载页面时,我只会得到一个空格,上面写着"抱歉发生错误".如果我使用"getDelete"格式化程序删除最后一个字段,则datagrid会很好地填充.我不确定我做错了什么,所以任何帮助都将不胜感激.
你在getDelete函数中犯了几个错误:
我认为这对你有用:
function getDelete(item) {
return "<button onclick=\"location.href='/report?command=delete&reportNo="
+ item + "'\">Delete</button>";
}
Run Code Online (Sandbox Code Playgroud)