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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamically build grid - hide column dynamically

Thread ID:

Created:

Updated:

Platform:

Replies:

144010 Apr 14,2019 06:13 PM UTC Apr 22,2019 06:14 AM UTC JavaScript - EJ 2 3
loading
Tags: Grid
Travis
Asked On April 14, 2019 06:13 PM UTC

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.

Thavasianand Sankaranarayanan [Syncfusion]
Replied On April 15, 2019 11:15 AM UTC

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. 


Travis
Replied On April 20, 2019 04:50 PM UTC

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

Thavasianand Sankaranarayanan [Syncfusion]
Replied On April 22, 2019 06:14 AM UTC

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon