Jqgrid获取我们输入的值并更改表单的可编辑属性 [英] Jqgrid getting value that we entered and change the editable attribute of a form

查看:184
本文介绍了Jqgrid获取我们输入的值并更改表单的可编辑属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,但是我遇到了这两个问题.我希望你们能帮助我.

excuse me guys, but i'm having these two problems. i hope you guys can help me with this.

这是我的代码的一部分

jQuery("#VWWMODULE").jqGrid(
{
url:'loadstatic.php?q=2&t=CORE_VW_WMODULE',
datatype: "json", 
mtype: "POST", 
colNames:['Id', 'From Range', 'To Range'],
colModel:
[
    {
        name:'id',
        index:'id',
        width:7,
        editable:true,
        edittype:'text',
        editrules:{required:true},
        editoptions:{maxlength:7, size:7},
        formoptions:{rowpos:1, elmprefix:'  '},
        key:true
    },
    {
        name:'rangefrom',
        index:'rangefrom',
        width:7,
        editable:true,
        edittype:'text',
        editrules:{required:true, number:true},
        editoptions:{maxlength:7, size:7},
        formoptions:{rowpos:6, elmprefix:'  '}
    },
    {
        name:'rangeto',
        index:'rangeto',
        width:7,
        editable:true,
        edittype:'text',
        editrules:{required:true, number:true, custom:true, custom_func:frtid},
        editoptions:{maxlength:7, size:7},
        formoptions:{rowpos:7,elmprefix:'  '}
    }
]

  1. 正如您在"rangeto"中看到的那样,我正在进行自定义验证.这种验证实际上很简单.它只需要检查我们输入的"rangeto"的值是否大于"rangefrom"的值.现在如何从"rangefrom"中获取值,以便可以与自定义验证功能中"rangeto"中的值进行比较?

  1. as you can see in the 'rangeto' i'm having a custom validation. this validation is simple actually. it just needs to check whether the value of 'rangeto' that we input is greater than the value of 'rangefrom'. now how can i get the value from 'rangefrom' so i can compare it with value from 'rangeto' in the custom validation function?

是关于索引'id'的.它用作表的主键.因此在编辑模式下不应更改它.我说的是在添加模式下,用户可以随时输入它.但是一旦他提交了该值,就无法更改.在编辑模式下,用户仍然可以看到"id"值,但是由于它是不可编辑的,因此他无法更改它.该怎么办?

for my second question is about index 'id'. it used as a primary key for a table. so it shouldn't be changed when in editing mode. i'm saying when in add mode, a user can input it anyway he want. but once he submit it, the value can't be changed. in edit mode, the user can still see the 'id' value but he can't change it because it is ineditable. how can this be done?

编辑

好的,现在我有另一个问题.这是一个简单的问题.

okay, now i'm having another problem. this is a simple question though.

  1. 如何使仅在添加模式下调用的自定义验证功能?原因是我的函数在编辑模式下不应调用时会给出错误消息

你们中的任何一个都可以帮助我解决我遇到的这3个问题吗?

can any of you guys please help me with these 3 problems that i had?

编辑

推荐答案

我想,您的主要问题是编辑后仅更改网格中的id.

I suppose, that your main problem now is only changing of id in the grid after editing.

首先,非常重要的一点是,您必须写下所有问题:使用哪种编辑模式,以及是否从服务器(datatype: "json")加载数据时是否使用loadonce: true.

First of all it's extremely important that you write in all your questions: which editing mode you use and whether you use loadonce: true if you load data from the server (datatype: "json").

由于使用colModel中的formoptions选项,因此只能间接地假设您使用表单编辑模式.表单编辑具有reloadAfterSubmit选项(请参见文档),默认值为true.这意味着jqGrid在成功提交一行的编辑后重新加载了网格的全部内容.该设置简化了与服务器的接口.如果您使用默认选项,则ID编辑将不会有问题,编辑后的数据正确排序也将不会有任何问题.

Only indirectly one can suppose that you use form editing mode because you use formoptions options in colModel. Form editing has reloadAfterSubmit option (see the documentation) which default value is true. It means that jqGrid reload the whole content of the grid after successful submitting of editing of one row. The setting simplify interface to the server. If you use the default option then you will have no problem with id editing and no problem with correct sorting of data after editing.

如果您决定使用reloadAfterSubmit选项,则必须做其他工作.服务器应使用新值id进行响应.如果数据库中保存数据,id通常由数据库生成.您必须实现 afterSubmit 回调,该回调应解码为新从服务器响应中返回id并将其返回.

If you do decide to use reloadAfterSubmit option then you have to do additional work. The server should response with new value of id. The id will be typically generated by database in case of holding data in the database. You have to implement afterSubmit callback which should decode new id from the server response and return it.

如果您确实使用内联编辑并且需要更改id,那么我会将您转发到答案.该示例中的aftersavefunc回调包含修改id的代码.

If you do use inline editing and need to change id then I would forward you to the answer. aftersavefunc callback from the example contains the code which modify id.

已更新:我见过

UPDATED: I'v seen here that you asked the same question in the trirand forum. I wanted shortly comment one point from the Tony's answer.

每个添加或编辑"表单都包含带有数据的表(另一个表包含在表单底部看到的按钮).该表的前两行和最后一行几乎都是隐藏的,并且包含(或可以包含)有用的信息:

Every Add or Edit form contains table with the data (another table contains buttons which one see at the bottom of the form). The first two and the last one rows of the table are mostly hidden and contains (or can contains) helpful information:

例如,最后一行包含带有id="id_g"的输入字段.您没有列id的行存在事件(例如在网格中).因此,$("#id_g").val()包含编辑行的rowid.添加对话框在该位置包含字符串"_empty".

For example the last row contains input field with id="id_g". The row exist event you don't have the column id (like in your grid). So $("#id_g").val() contains the rowid of the editing row. Add dialog contains the string "_empty" on the place.

更新2 :如果您需要在添加和编辑"表单中显示id字段,但将其设置为只读,则只需在id列中使用readonly: 'readonly'属性即可(请参见

UPDATED 2: If you need to display id field in Add and Edit form but make it readonly you need just use readonly: 'readonly' property for id column (see here). The next problem: you should use recreateForm: true property for both Add and Edit forms.

我不建议您使用reloadAfterSubmit: true,但是如果您确实需要使用该选项,则应该从服务器(从 savewmodule.php )返回新添加的行的ID和您必须使用afterSubmit回调从服务器响应中获取新的ID,并以记录的方式将其返回(return [true, "", new_id];).另外,保存行后,必须设置网格的"id"列的内容.您应该修改afterSubmit回调的postdata参数的id属性.

I don't recommend you to use reloadAfterSubmit: true, but if you really need to use the option you should returns from the server (from savewmodule.php) the id of new added row and you have to use afterSubmit callback to get the new id from the server response and return it in documented way (return [true, "", new_id];). Additionally you have to set content of "id" column of grid after saving of row. You should modify id property of postdata parameter of afterSubmit callback.

这篇关于Jqgrid获取我们输入的值并更改表单的可编辑属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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