Skip to main content

Hidden Columns in jqGrid



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





Source: Tips4all

Comments

  1. I just want to expand on queen3's suggestion, applying the following does the trick:

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


    Scenario #1:


    Field must be visible in the grid
    Field must be visible in the form
    Field must be read-only


    Solution:

    colModel:[
    {name:'providerUserId',index:'providerUserId', width:100,editable:true, editrules:{required:true}, editoptions:{ dataInit: function(element) { jq(element).attr("readonly", "readonly"); } }},
    ],


    The providerUserId is visible in the grid and visible when editing the form. But you cannot edit the contents.



    Scenario #2:


    Field must not be visible in the grid
    Field must be visible in the form
    Field must be read-only


    Solution:

    colModel:[
    {name:'providerUserId',index:'providerUserId', width:100,editable:true, editrules:{required:true, edithidden:true}, hidden:true, editoptions:{ dataInit: function(element) { jq(element).attr("readonly", "readonly"); } }},
    ]


    Notice in both instances I'm using jq to reference jquery, instead of the usual $. In my HTML I have the following script to modify the variable used by jQuery:

    <script type="text/javascript">
    var jq = jQuery.noConflict();
    </script>

    ReplyDelete
  2. 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.

    ReplyDelete
  3. 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.

    ReplyDelete
  4. 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.

    ReplyDelete
  5. 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.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex