EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jaimi on January 28, 2015, 10:15:13 PM



Title: column hiding depending on variable
Post by: jaimi on January 28, 2015, 10:15:13 PM
Hi, I'd like to display/hide particular columns within a datagrid depending on a variables value.
For example, when vSITE == 1 then display field OLT30A001T_KEY, otherwise hide it.
How to?
THX, Jaimi

---->
 $(function(){
 
  var vPRK = $('#vPRK').val();
  var vSITE = $('#vSITE').val();
  var vCMD = $('#vCMD').val();
  //alert(vPRK);

 /**********************************************************************************
                                     edatagrid
 **********************************************************************************/
 $('#edgNews').edatagrid({
  title : 'Neuigkeiten',
  iconCls:'icon-Pferd',
  width:'100%', 
  height:'auto',
  collapsible : 'true',

  columns:[[ 
    {field:'OLT30A001T_KEY',title:'PferdKey',width:080,sortable:'true',hidden:'true'}
   ,{field:'OLT30A003T_KEY',title:'NewsKey',width:080,sortable:'true',hidden:'true'}
   ,{field   :'NWS_STATUS'
      ,title   :'Status'
      ,width   :060
      ,sortable:'true'
     , align: 'center'
      ,editor  : {
        type   :'combobox'
      ,options:{
         valueField:'KEY'
        ,textField:'NWS_STATUS'
       ,url:'pferd.lkp.nws.json'
       ,required:true
       ,editable:true
       ,prompt:'Status...'
       ,missingMessage: 'Wählen Sie den Status aus.'
      }
     }//editor
    ,formatter:function(value,row){return value;}//formatter
   }         
...


Title: Re: column hiding depending on variable
Post by: stworthy on January 29, 2015, 12:54:59 AM
Please call 'showColumn' or 'hideColumn' methods to display or hide the special column.


Title: Re: column hiding depending on variable
Post by: jaimi on January 29, 2015, 04:21:01 AM
I still doesn't get it. I tried:

  ,onBeforeLoad: function() {
     alert("onBeforeLoad: " + vSITE);
     $(this).datagrid('hideColumn',{field:'PFA_NAME'});
  }
  ,onLoadSuccess: function(objects) {
     alert("onLoadSuccess: " + vSITE);
     $(this).datagrid('hideColumn',{field:'PFA_NAME'});
  }

could you pleas make an example.
THX Jaimi


Title: Re: column hiding depending on variable
Post by: stworthy on January 29, 2015, 07:58:43 AM
Please use the code below instead.
Code:
$(this).datagrid('hideColumn','PFA_NAME');