How to hide a jqgrid column dynamically

前端 未结 5 1351
醉酒成梦
醉酒成梦 2021-01-11 11:19

I am implementing jqgrid in my asp.net MVC web application.

In my grid i have two columns edit and delete. The delete should be visible only if the user is logged as

相关标签:
5条回答
  • 2021-01-11 11:21

    This is not the best practice to use js to manage your security. You should not show this column on your server side!

    0 讨论(0)
  • 2021-01-11 11:22

    I had to dive into some legacy stuff today. One of the requirements was to conditionally set the visibility of some columns. There was a drop down on the page that set a category parameter in the where clause for the grid. Long story short, watching the change event of the drop down wasn't possible making most of the methods in the answers here invalid.

    I was able to use a ternary in the hidden param to set the visibility.

    {
        name: 'mfg',
        index: 'mfg',
        width: 150,
        sortable: true,
        hidden: $('#evCategory').val() == 'Calibration' ? false : true
    },
    

    And it simply evals to if the dropdown has a value of calibration hidden should be false, if calibration is not the value hidden should be true.

    Might also be able to shorten it to;

    !$('#evCategory').val() == 'Calibration' || true
    

    Although I haven't tested that.

    0 讨论(0)
  • 2021-01-11 11:30

    This one worked:

    $("#list").hideCol("ColumnName")
    
    0 讨论(0)
  • 2021-01-11 11:33

    Newer API

    jQuery("#list").jqGrid('hideCol',["ColumnName","ColumnName2"]);
    

    Older API

    $("#list").hideCol("ColumnName")
    
    0 讨论(0)
  • 2021-01-11 11:35

    Use this code,

    jQuery("#list").jqGrid('hideCol',["colModel1_name","colModel2_name"]);
    jQuery("#list").jqGrid('showCol',["colModel1_name","colModel2_name"]);
    

    May this help you.

    0 讨论(0)
提交回复
热议问题