gpt4 book ai didi

jqGrid - 内联编辑和陷印编辑规则

转载 作者:行者123 更新时间:2023-12-05 00:07:05 26 4
gpt4 key购买 nike

在我的情况下,我需要允许用户编辑网格中的各种单元格,然后稍后将整个网格保存到服务器。我已经通过内联编辑和保存到“clientArray”几乎解决了这个问题。但是,我正在尝试使用 editRules 并且遇到了一些问题。

如果我使一列可编辑,并使用编辑规则要求它是一个数字

{ name: 'Value', index: 'Value', width: 50, sortable: true,edittype: 'text',
editable: true, editoptions: { maxlength: 10 },
editrules:{number: true},
formatter:currencyFmatter, unformat:unformatCurrency },

我在 onSelectRow 中控制编辑和保存事件:
onSelectRow: function(id){
if(id && id!==lastSel){
jQuery("#Groups").saveRow(lastSel,true,'clientArray');
jQuery("#Groups").editRow(id,true);
}
lastSel=id
},

然后我使用按钮单击事件来保存网格。一切都很好,直到我将一个非数字值放入值单元格然后单击它下面的行。它抛出警告框并停止保存,但它并没有阻止我更改行。所以我现在有两行打开进行编辑。有没有办法捕获编辑规则错误,以便我可以在移动到下一行之前处理它。
我尝试将这些函数与 saveRow (succesfunc, aftersavefunc, errorfunc, afterrestorefunc) 一起使用,其中都说在将数据保存到服务器后触发,这似乎不适用于“clientArray”。

基本上,当保存到“clientArray”时,我需要找到一种方法来验证内联编辑中的数据,并且非常感谢信息、建议,尤其是示例。

谢谢。

玩了一段时间后,我决定编辑规则不能很好地与内联编辑一起使用。所以,正如你所建议的,我制定了自己的验证程序。诀窍是弄清楚如何获取编辑行的值。

我现在想弄清楚的一件事是如何让焦点回到 Value 列。回到文档!
              if(id && id!==lastSel){
//dont save if first click
if (lastSel != -1) {
//get val of Value to check
var chkval = jQuery("#"+lastSel+"_Value").val() ;
// verify it is a number

if (isNaN(chkval)) {//If not a number
//Send Validation message here

//Restore saved row
jQuery("#Grid").restoreRow(lastSel);
//Return to failed save row
jQuery("#Grid ").setSelection(lastSel,false);
//reopen for editing
jQuery("#Grid ").editRow(lastSel,true);
//Note - dont reset lastSel as you want to stay here }
else {
// If number is good, proceed to save and edit next
jQuery("#Grid ").jqGrid('saveRow',lastSel, checksave, 'clientArray', {}, null, myerrorfunc);
jQuery("#Grid ").editRow(id,true);
lastSel=id;
};
isDirty = true;
};
else {
//first click - open row for editing
alert("new Edit")
jQuery("#Grid ").editRow(id,true);
lastSel=id;}
}

最佳答案

为了解决这个问题,我使用了插件 jquery.limitkeypress.min.js。

onSelectRow: function(id){
if(id && id!==lastsel){
jQuery('#treegrid').jqGrid('restoreRow',lastsel);
jQuery('#treegrid').jqGrid('editRow',id, true);
$("input[name=Presupuesto]").limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ });
lastsel=id;
}
}

其中,“Presupuesto”是我让用户输入数据的列的名称。

它工作得很好...

关于jqGrid - 内联编辑和陷印编辑规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2359011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com