jqGrid-内联编辑和陷阱编辑规则 [英] jqGrid - inline edit and trapping edit rules

查看:85
本文介绍了jqGrid-内联编辑和陷阱编辑规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my situation, I need to allow users to edit various cells in the grid and then save the whole grid to the server later. I have pretty much solved this issue with inline editing and saving to ‘clientArray’. However, I am trying to use the editRules and have run into some issues.

如果我将一列设置为可编辑,并使用编辑规则要求该列必须为数字

If I make a column editable, and use edit rules to require it to be a number

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

,然后在onSelectRow事件中控制编辑和保存:

and I control editing and saving in the onSelectRow event:

onSelectRow: function(id){
    if(id && id!==lastSel){
        jQuery("#Groups").saveRow(lastSel,true,'clientArray');   
        jQuery("#Groups").editRow(id,true);
    }  
    lastSel=id
},

然后我使用按钮单击事件来保存网格.一切正常,直到我将非数字值放入值"单元格,然后单击其下面的行.它会弹出警告框并停止保存,但不会阻止我更改行.因此,我现在有两行可供编辑.有没有办法捕获editrule错误,这样我就可以在移至下一行之前进行处理.
我尝试过将函数与saveRow一起使用(succesfunc,aftersavefunc,errorfunc,afterrestorefunc),在将数据保存到服务器后所有这些函数均会触发,这似乎不适用于"clientArray".

I then use a button click event to save the grid. Everything works great untill I put a non-numeric value into the Value cell then click on the row below it. It throw as warning box up and stop the save, but it does not stop me from changing rows. So I now have two rows open for editing. Is there a way to trap the editrule error so I can handle it before moving to the next row.
I have tried to use the functions with saveRow (succesfunc, aftersavefunc, errorfunc, afterrestorefunc), of which all say fire after data is saved to server, which does not appear to work for ‘clientArray’.

基本上,当保存到"clientArray"中时,我需要找到一种方法来验证数据的内联编辑,信息,建议,尤其是示例,将不胜感激.

Basically, I need to find a way to validate the data in inline editing when saved to ‘clientArray’ and information, suggestions, and particularly, examples would be greatly appreciated.

谢谢.

玩了一段时间之后,我决定编辑规则不能与内联编辑一起很好地工作.因此,正如您建议的那样,我制定了自己的验证例程.诀窍是弄清楚如何获得已编辑行的值.

After playing for awhile, I decided edit rules dont work so well with inLine Editing. So, as you suggested, I made my own validation routine. The trick was figuring out how to get the value of the edited row.

我现在要弄清楚的一件事是如何使焦点回到值"列.返回文档!

The one thing I am trying to figure out now is how to get the focus to go back to the Value column. Back to the documentation!

              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.

in order to resolve this, I used the plugin 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"是我向用户输入数据的列的名称.

where, "Presupuesto" is the name of the column where I let input data to the user.

效果很好...

这篇关于jqGrid-内联编辑和陷阱编辑规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆