使用的脚本是
<script type="text/javascript">
var lastSelection;
var idCategoria;
var nomeCategoria;
function editRow(id) {
if (id && id !== lastSelection) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
if (document.getElementById(lastSelection + "_NomeCategoria") != null) {
if ( document.getElementById(lastSelection + "_NomeCategoria").value != undefined ) {
var objeto = document.getElementById(lastSelection + "_NomeCategoria");
idCategoria = objeto.value;
nomeCategoria = objeto[objeto.selectedIndex].text;
}
}
if (lastSelection != undefined) {
grid.updateGridRows("{IdCategoria:" + idCategoria + "}", lastSelection);
grid.saveRow(lastSelection, false);
//grid.setCell(lastSelection, "IdCategoria", idCategoria);
//grid.setRowData(lastSelection, "{IdCategoria:" + idCategoria + "}");
}
try
{
grid.restoreRow(lastSelection, defineCategoria);
}
catch(err)
{
alert(err.description);
}
grid.editRow(id, true, selecionaCategoria);
lastSelection = id;
}
}
function selecionaCategoria(id) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
var linha = grid.getRowData(id);
var idCategoria = linha.IdCategoria;
var comboCategorias = document.getElementById(id + "_NomeCategoria");
if (idCategoria != "" && idCategoria != undefined) {
try {
for (var i = 0; i < comboCategorias.childNodes.length; i++) {
if (comboCategorias.childNodes[i].value == idCategoria) {
comboCategorias.childNodes[i].selected = true;
break;
}
}
}
catch (err) {
alert(err.description);
}
}
}
function defineCategoria(id) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
grid.setCell(id, "NomeCategoria", DefineUrlCategoria(idCategoria, nomeCategoria));
}
// The FormatFunction for CustomFormatter gets three parameters
// cellValue - the original value of the cell
// options - as set of options, e.g
// options.rowId - the primary key of the row
// options.colModel - colModel of the column
// rowData - array of cell data for the row, so you can access other cells in the row if needed
function DefineUrl(cellValue, options, rowObject) {
var caminho = "";
if (isArray(rowObject)) {
if (rowObject[1] != "" && rowObject[1] != undefined) {
//var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + rowObject[1] + "'>" + cellValue + "</a>";
caminho = DefineUrlCategoria(rowObject[1], cellValue);
}
else {
caminho = cellValue;
}
}
else {
if (idCategoria != "0") {
caminho = DefineUrlCategoria(idCategoria, nomeCategoria);
}
else {
caminho = nomeCategoria;
}
}
return caminho;
}
function isArray(o) {
return (typeof (o.length) == "undefined") ? false : true;
}
function DefineUrlCategoria(idCategoria, nomeCategoria) {
var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + idCategoria + "'>" + nomeCategoria + "</a>";
return caminho;
}
</script>
当行未处于编辑模式时,第五列显示链接,编辑时显示下拉列表。要在下拉列表中选择正确的项目,请使用具有来自数据库的ID的第二列。
问题是更改项目并将其保存到数据库后,此列值不会更改。如何在grid.saveRow(lastSelection,false)之后执行此操作; ?
感谢。
答案 0 :(得分:1)
我找到了解决方案!
我更改了以下代码
if (lastSelection != undefined) {
grid.updateGridRows("{IdCategoria:" + idCategoria + "}", lastSelection);
grid.saveRow(lastSelection, false);
//grid.setCell(lastSelection, "IdCategoria", idCategoria);
//grid.setRowData(lastSelection, "{IdCategoria:" + idCategoria + "}");
}
到此
if (lastSelection != undefined) {
grid.setRowData(lastSelection, {IdCategoria:idCategoria});
grid.saveRow(lastSelection, false);}
问题在于我将第二个参数作为字符串传递。