We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamically build grid - hide column dynamically

I am attempting to hide a column dynamically. I created a new grid object as seen below.  The 'objGridData' is built dynamically meaning the content and number of columns can change.  What I need is a hidden key column that when I select a row, I can read that column key and do something.

Is there a way that when I build the 'objGridData' to designate a column to be hidden?


var gridObj = new ej.grids.Grid({
        dataSource: objGridData,
        allowPaging: true,
        selectionSettings: { mode: 'Both' },
        height: 500
    });



Thanks.

3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team April 15, 2019 03:15 AM

Hi Travis, 

Greetings from Syncfusion support. 

We can achieve your requirement using the load, dataBound, rowSelected event of Grid. In the dataBound we can hide the column using the visible property of columns API in Grid.  

Refer the below code example. 


var flag = false; 
    window.orderDataSource[0].OrderDate = null; 
    var grid = new ej.grids.Grid({ 
        dataSource: window.orderDataSource, 
        allowPaging: true, 
        selectionSettings: { mode: 'Both' }, 
        height: 500, 
        load: load, 
        dataBound: dataBound 
         
    }); 
    function load(args){ 
      flag = this.isInitial; 
    } 
    function dataBound(args){ 
      if(flag){ 
        this.columns[0].visible = false; 
        this.refreshColumns(); 
        flag = false; 
      } 
    } 
     
    grid.appendTo('#Grid'); 


Refer the help documentation. 




In the rowSelected event we can get the current selected record in the arguments of those event. 

Refer the below code example. 


var flag = false; 
    window.orderDataSource[0].OrderDate = null; 
    var grid = new ej.grids.Grid({ 
        dataSource: window.orderDataSource, 
        allowPaging: true, 
        selectionSettings: { mode: 'Both' }, 
        height: 500, 
         
        rowSelected: rowSelected 
    }); 
     
    function rowSelected(args){ 
      console.log(args.data); 
    } 
    grid.appendTo('#Grid'); 


Refer the help documentation. 


We have prepared a simple sample in the following stackblitz link. 


Please let us know if you need further assistance on this. 

Regards, 
Thavasianand S. 



TR Travis April 20, 2019 08:50 AM

Thanks for the update - this works as expected.  I am using an Event listener instead of rowSelected, and it all works.


TS Thavasianand Sankaranarayanan Syncfusion Team April 21, 2019 10:14 PM

Hi Travis, 
 
We are happy that the problem has been solved. 
 
Please get back to us if you need any further assistance.  
                          
Regards, 
Thavasianand S.

Loader.
Live Chat Icon For mobile
Up arrow icon