Jquery 如何在jqgrid中将不可编辑的值发送到服务器端?

Jquery 如何在jqgrid中将不可编辑的值发送到服务器端?,jquery,jqgrid,Jquery,Jqgrid,我有一个简单的网格,它有来自数据库的4列:ID、Name、CreationDate、ModificationDate。所有这些字段都会显示,但只有名称是可编辑的。ID和日期显示为纯文本 我遇到的问题是记录何时被修改。只有名称字段被传递到服务器端。CreationDate作为默认值01/01/0001发送,而不是当前具有的值 这是我的剧本: <script type="text/javascript"> $(function () { $("#departamentos").j

我有一个简单的网格,它有来自数据库的4列:ID、Name、CreationDate、ModificationDate。所有这些字段都会显示,但只有名称是可编辑的。ID和日期显示为纯文本

我遇到的问题是记录何时被修改。只有名称字段被传递到服务器端。CreationDate作为默认值01/01/0001发送,而不是当前具有的值

这是我的剧本:

<script type="text/javascript">
$(function () {
    $("#departamentos").jqGrid({
        url: "@Url.Action("List")",
        datatype: "json",
        mtype: "GET",
        colNames: ["@Html.DisplayNameFor(model => model.dep_id)",
                   "@Html.DisplayNameFor(model => model.dep_nombre)",
                   "@Html.DisplayNameFor(model => model.dep_creado_el)",
                   "@Html.DisplayNameFor(model => model.dep_modificado_el)",
                   " "],
        colModel: [
            { name: "dep_id", index: "dep_id", key : true, sortable:false, editable:false, editoptions:{readonly:true,size:10}, width: 90 },
            { name: "dep_nombre", index: "dep_nombre", editable:true, width: 250 },
            { name: "dep_creado_el", index: "dep_creado_el", width: 100, align: "center", formatter: "date" },
            { name: "dep_modificado_el", index: "dep_modificado_el", width: 100, align: "center", formatter: "date" },
            { name: 'acciones', width: 58, fixed: true, sortable: false, resize: false, formatter: 'actions', formatoptions: { keys: true } }
        ],
        jsonReader: {
            repeatitems: false
        },
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "dep_nombre",
        sortorder: "asc",
        viewrecords: true,
        gridview: true,
        autoencode: true,
        multiselect: true,
        caption: "Departamentos",
        editurl: "@Url.Action("AjaxEdit")",
    });

    $("#departamentos").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });

    $.jgrid.edit.addCaption = "Agregar Departamento";
    $.jgrid.edit.editCaption = "Modificar Departamento";
    $.jgrid.edit.saveData = "¡El departamento fue modificado! ¿Almacena los cambios?";

    $.jgrid.formatter.date.newformat = 'd-m-Y H:i';

}); 
</script>

$(函数(){
$(“#departmentos”).jqGrid({
url:“@url.Action(“列表”)”,
数据类型:“json”,
mtype:“获取”,
colNames:[“@Html.DisplayNameFor(model=>model.dep_id)”,
“@Html.DisplayNameFor(model=>model.dep_nombre)”,
“@Html.DisplayNameFor(model=>model.dep_creado_el)”,
“@Html.DisplayNameFor(model=>model.dep\u modificado\u el)”,
" "],
colModel:[
{name:“dep_id”,index:“dep_id”,key:true,sortable:false,editable:false,editoptions:{readonly:true,size:10},width:90},
{名称:“dep_nombre”,索引:“dep_nombre”,可编辑:true,宽度:250},
{名称:“dep_creado_el”,索引:“dep_creado_el”,宽度:100,对齐:“中心”,格式化程序:“日期”},
{名称:“dep_modificado_el”,索引:“dep_modificado_el”,宽度:100,对齐:“中心”,格式化程序:“日期”},
{name:'acciones',width:58,fixed:true,sortable:false,resize:false,formatter:'actions',formattoptions:{keys:true}
],
jsonReader:{
重复项:false
},
寻呼机:“#寻呼机”,
rowNum:10,
行列表:[10,20,30],
sortname:“副主席”,
分拣员:“asc”,
viewrecords:是的,
gridview:没错,
自动编码:正确,
多选:对,
描述:“部门”,
editurl:“@Url.Action”(“AjaxEdit”)”,
});
$(“#departmentos”).jqGrid('navGrid','#pager',{edit:true,add:true,del:true});
$.jgrid.edit.addCaption=“Agregar departmento”;
$.jgrid.edit.editCaption=“修改部门”;
$.jgrid.edit.saveData=““修改后的部门!”Almacena los cambios?”;
$.jgrid.formatter.date.newformat='d-m-Y H:i';
}); 
任何帮助都将不胜感激 谢谢
Jaime

有很多方法可以解决这个问题

最简单的方法之一是使
dep\u creado\u el
可编辑。在这种情况下,编辑/添加表单将具有包含数据的行。您可以在
afterShowForm
beforeShowForm
回调中隐藏该行。因此,您可以执行与中相同的操作:


另一种方法是扩展
onclickSubmit
callback或
serializeEditData

Hi.中的数据。。第一种解决方案不好,因为它会隐藏数据。我只需要将其显示为纯文本。通过扩展,您的意思是我必须在单击sobmit时动态添加一个隐藏字段吗?@jstuardo:您现在使用的编辑表单仅显示
dep_nombre
列的数据。我不建议在
dep\u creado\u el
列中添加
hidden:true
属性。您需要在列中添加editable:true属性。它将使用内容为
dep_creado_el
列的行扩展编辑表单,但使用
$(''tr#dep_creado_el').hide()隐藏该行在ShowForm
之前的
内部。因此,从用户的查看点来看,已归档的
dep_creado_el
将不可编辑,但有关该列的数据将像所有可编辑列一样发送到服务器。
beforeShowForm: function () {
    $('#tr_dep_creado_el').hide();
}