隐藏jqGrid显示中的列,但在编辑/添加屏幕中显示它?

时间:2013-12-12 02:30:37

标签: jqgrid

在我的jqGrid中,我想从我的模型中传入5行并在网格中显示3行但是在编辑中显示所有5行并添加jqGrid生成的弹出窗口。我知道我可以在hidden: true设置中添加colModel属性以防止它出现,但这也会从弹出窗口隐藏它。有没有办法从网格中隐藏列,但在添加或编辑数据时显示它?

我的网格代码:

<script type="text/javascript">
    $( document ).ready( function ()
    {
        $( '#Sections' ).jqGrid( {
            url: '@Url.Action("GetData")',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['ID', 'RouteName', 'Title', 'File', 'Description'],
            colModel: [
                        { name: 'ID', index: 'ID', width: 10, sorttype: 'int' },
                        { name: 'RouteName', index: 'RouteName', width: 50, editable: true, edittype: 'text'},
                        { name: 'Title', index: 'Title' },
                        { name: 'File', index: 'File', hidden: true },
                        { name: 'Description', index: 'Description', hidden: true }
            ],
            autowidth: true,
            height: '100%',
            pager: $( '#SectionsPager' ),
            sortname: 'ID',
            viewrecords: true,
            loadonce: true,
            ignoreCase: true,
            multiSort: true,
        } );
        $( '#Sections' ).jqGrid( 'navGrid', '#SectionsPager',
            //enabling buttons
            { add: true, del: false, edit: true, search: true },
           //add options
           { width: 'auto' },
           //edit options
           { width: 'auto' },
           //delete options
           {}
        );
    } );
</script>

2 个答案:

答案 0 :(得分:4)

Via Oleg的回答

Sending additional parameters to editurl on JQgrid

hidden: true, editable: true, editrules: { edithidden: true}, hidedlg: true

editrules: { edithidden: true}部分会在编辑时“打开”您的列。

答案 1 :(得分:0)

您可以在添加/修改中使用beforeShowForm并将其隐藏起来

beforeShowForm:  function(form) { 
$("#tr_columnname").hide(); 
    $("#tr_columnname").show();
}
相关问题