【发布时间】:2013-02-22 15:02:58
【问题描述】:
我现在从 jqGrid 开始,有一些我无法理解的问题。
我正在做一个可内联编辑的网格,但它只是编辑第一行。如果我单击任何行,它只会编辑第一行。我不知道发生了什么,如果有人可以告诉我如何一步一步地做,那将对我有很大帮助。
这是我的代码的一部分:
$(function(){
var lastSel;
$("#list").jqGrid({
url:'php.php',
datatype: 'xml',
mtype: 'POST',
colNames:['ac_n_quad', 'ac_l_circ', 'ac_n_circ', 'ac_fin_g', 'ac_pot', 'ac_volt', 'ac_n_polos', 'ac_t_prot', 'ac_v_prot', 'ac_cabo',
'ac_fd', 'ac_fp', 'ac_ctr', 'ac_pot_a', 'ac_pot_b', 'ac_pot_c', 'ac_pos_1', 'ac_pos_2', 'ac_calc'],
colModel :[
{name:'ac_n_quad', index:'ac_n_quad', width:110, align:'right', editable:true, key:true},
{name:'ac_l_circ', index:'ac_l_circ', width:65, align:'right', editable:true},
{name:'ac_n_circ', index:'ac_n_circ', width:120, align:'right', editable:true, key: true},
{name:'ac_fin_g', index:'ac_fin_g', width:60, align:'right', editable:true},
{name:'ac_pot', index:'ac_pot', width:55, align:'right', editable:true},
{name:'ac_volt', index:'ac_volt', width:60, align:'right', editable:true},
{name:'ac_n_polos', index:'ac_n_polos', width:100, align:'right', editable:true},
{name:'ac_t_prot', index:'ac_t_prot', width:100, align:'right', editable:true},
{name:'ac_v_prot', index:'ac_v_prot', width:70, align:'right', editable:true},
{name:'ac_cabo', index:'ac_cabo', width:60, align:'right', editable:true},
{name:'ac_fd', index:'ac_fd', width:55, align:'right', editable:true},
{name:'ac_fp', index:'ac_fp', width:55, align:'right', editable:true},
{name:'ac_ctr', index:'ac_ctr', width:60, align:'right', editable:true},
{name:'ac_pot_a', index:'ac_pot_a', width:70, align:'right', editable:true},
{name:'ac_pot_b', index:'ac_pot_b', width:70, align:'right', editable:true},
{name:'ac_pot_c', index:'ac_pot_c', width:70, align:'right', editable:true},
{name:'ac_pos_1', index:'ac_pos_1', width:70, align:'right', editable:true},
{name:'ac_pos_2', index:'ac_pos_2', width:70, align:'right', editable:true},
{name:'ac_calc', index:'ac_calc', width:65, align:'right', editable:true}],
cmTemplate: { align: 'center', editable: true },
onSelectRow: function(id){
if(id && id !== lastSel){
$(this).restoreRow(lastSel);
lastSel = id;
}
$(this).editRow (id, true);
},
prmNames: {ac_n_quad: "id"},
editurl:'clientArray',
autowidth: 'true',
height: 'auto',
rowNum: 10,
rowList: [10,20,30, 40, 50, 60, 70, 80, 90, 100],
sortname: 'ac_n_quad, ac_n_circ',
sortorder: 'asc',
pager: '#pager',
viewrecords: true,
gridview: true,
caption: 'Table circ_69'
});
jQuery('#list').jqGrid('gridResize');
jQuery('#list').jqGrid('navGrid', '#pager', {
edit: true,
add: true,
del: true,
search: false,
refresh: false
});
});
【问题讨论】:
-
因此,当您选择除第一或第四之外的任何行时,它们在网格中无法编辑?
-
没有。当我选择任何一行时,只有第一行在网格中变得可编辑。
-
当您选择不同的行时,您是否看到您的 id 发生了变化?您在 onSelectRow 中的 Id 应该是所选行的 rowId。
-
谢谢@Mark 我看到我做错了什么......我没有一个ID来控制行。我之前定义的 id 有多个值,因此它无法正常工作...感谢您的帮助 :D 最诚挚的问候 :)
标签: jqgrid inline-editing