Hidden Columns in jqGrid

前端 未结 7 1851
不思量自难忘°
不思量自难忘° 2020-12-12 18:20

Is there any way to hide a column in a jqGrid table, but have it show as read-only when the row is edited in the form editor modal dialog?

相关标签:
7条回答
  • 2020-12-12 18:29

    To hide the grid column

    jQuery("#validGrid").jqGrid('hideCol',str);
    
    0 讨论(0)
  • 2020-12-12 18:31

    You can use the following code to hide a table column..

    JQuery("tableName").hideCol("colName");
    

    And you can use the following code to show it again.

    JQuery("tableName").showCol("colName");
    

    For your question, you can call the hideCol() code on the document.ready(), and you can bind the showCol() code on the dialog's edit/click event.

    0 讨论(0)
  • 2020-12-12 18:31

    This thread is pretty old I suppose, but in case anyone else stumbles across this question... I had to grab a value from the selected row of a table, but I didn't want to show the column that row was from. I used hideCol, but had the same problem as Andy where it looked messy. To fix it (call it a hack) I just re-set the width of the grid.

    jQuery(document).ready(function() {
    
           jQuery("#ItemGrid").jqGrid({ 
                    ..., 
                    width: 700,
                    ...
            }).hideCol('StoreId').setGridWidth(700)
    

    Since my row widths are automatic, when I reset the width of the table it reset the column widths but excluded the hidden one, so they filled in the gap.

    0 讨论(0)
  • 2020-12-12 18:33

    Try to use edithidden: true and also do

    editoptions: { dataInit: function(element) { $(element).attr("readonly", "readonly"); } }
    

    Or see jqGrid wiki for custom editing, you can setup any input type, even label I think.

    0 讨论(0)
  • 2020-12-12 18:43

    This feature is built into jqGrid.

    setup your grid function as follows.

    $('#myGrid').jqGrid({
       ...
       colNames: ['Manager', 'Name', 'HiddenSalary'],
       colModel: [               
                   { name: 'Manager', editable: true },
                   { name: 'Price', editable: true },
                   { name: 'HiddenSalary', hidden: true , editable: true, 
                      editrules: {edithidden:true} 
                   }
                 ],
       ...
    };
    

    There are other editrules that can be applied but this basic setup would hide the manager's salary in the grid view but would allow editing when the edit form was displayed.

    0 讨论(0)
  • 2020-12-12 18:47

    It is a bit old, this post. But this is my code to show/hide the columns. I use the built in function to display the columns and just mark them.

    Function that displays columns shown/hidden columns. The #jqGrid is the name of my grid, and the columnChooser is the jqGrid column chooser.

      function showHideColumns() {
            $('#jqGrid').jqGrid('columnChooser', {
                width: 250,
                dialog_opts: {
                    modal: true,
                    minWidth: 250,
                    height: 300,
                    show: 'blind',
                    hide: 'explode',
                    dividerLocation: 0.5
                } });
    
    0 讨论(0)
提交回复
热议问题