我有几个允许User删除Item(实际上是行)的SlickGrids。这工作正常但当用户想要取消删除行时,我无法重新显示整个网格。这是删除行的相关代码:
// Modal Grid2 Remove rows
$('#removeBtnGrid2').click(function() {
for (var i = 1; i <= 2; i++) {
dataViewMG2.deleteItem(i);
}
invmodalgrid2.invalidate();
invmodalgrid2.render();
});
这是我用来重新显示网格的代码(这不起作用):
// XXXXXXXXXXXXXXXXXXXXXXX Load selected data into MODAL GRID 2
$('#addBtnGrid1').click(function() { /// this acts as a cancel btn
dataViewMG2.beginUpdate();
dataViewMG2.setItems(modaldata2);
dataViewMG2.refresh();
invmodalgrid2.render();
dataViewMG2.endUpdate();
}
我做错了什么?感谢
答案 0 :(得分:1)
首先,当我认为你的意思是({2} addBtnGrid1
时,你已经放置了addBtnGrid2
,其次,你是在处理服务器端来删除你的行吗?因为这似乎不是处理它的正确方法(虽然我不得不承认我没有尝试过你的代码)。我正在处理删除的方式直接将操作嵌入到接受/取消定义的columns
定义中的ID本身,例如:
columns1 = [
{id:'accnt_name', field:'accnt_name', name: "Account Name", width:90, sortable:true, sorter:sorterStringCompare} },
{id:"id", name:"", field:"id", width:20, formatter: function (r,c,id,def,datactx){ return "<a href='#' onclick='if (confirm(\"Really Delete?\")) removeClick("+id+","+r+")'><img src='/images/deletex_16.png' border='0' /></a>";} }
];
然后删除的函数(使用AJAX在PHP中调用服务器端)如下所示:
function removeClick(databaseId, gridRow) {
$.post('myajaxfile.php?action=delete', {id:databaseId}, function(ServerResponse) {
// if database return an error then display it to the user and undo the cell change
if(ServerResponse === undefined) {
alert("Deleting from database failed...");
}else {
if( parseInt(ServerResponse.affected_rows) < 1 || ServerResponse.error_msg != "" ) {
alert("Deleting from database failed...\n\nERROR Returned: "+ServerResponse.error_msg);
}else {
// success, update the datagrid view on screen
var item = dataView1.getItem(gridRow);//RowNum is the number of the row
dataView1.deleteItem( item.id );//RowID is the actual ID of the row and not the row number
grid1.invalidate();
grid1.render();
}
}
$('#loading').hide(); // hide the loading logo
}, "json")
.fail(function(ServerResponse) {
alert("Deleting from database failed...\n\nERROR Returned: "+ServerResponse.responseText);
$('#loading').hide(); // hide the loading logo
});
}
因此,如果DELETE在服务器端运行良好,我只刷新(渲染)网格...希望它有所帮助!我不认为向你展示要删除的PHP文件(服务器端),但如果你这样做,那么再问一次......