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

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

Java Urban Myths

Along the line of C++ Urban Myths and Perl Myths : What are the Java Urban Myths? That is, the ideas and conceptions about Java that are common but have no actual roots in reality . As a Java programmer, what ideas held by your fellow Java programmers have you had to disprove so often that you've come to believe they all learned at the feet of the same drunk old story-teller? Ideally, you would express these myths in a single sentence, and include an explanation of why they are false.

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...