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

Is it possible to do something to a viewModel property to automatically hide its column in the grid

I have a viewModel that contains a list of entities

public class MyEntity
{
     public int ID {get;set;}
     public string Name {get;set;}
     public string CellPhoneNo {get;set;}
}

If I setDataSource to grid, all columns are shown, as expected.  

What I would like to do it decorate my ID property with something like that

        [HiddenInput(DisplayValue = false)]

so it would not show at all.

Is it possible or will i need to generate all my DataColumns in my Razor file



3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 12, 2019 10:52 AM UTC

Hi Fred, 

Thanks for contacting Syncfusion support. 

Before providing a solution, please share the following details that will be helpful for us to validate and provide a solution as soon as possible. 

  • Do you want to hide the ID column in Grid or hide only when perform editing(hide the input element)?
  • Share the viewModel and Grid code example.

Regards, 
Seeni Sakthi Kumar S. 



FM Fred Morin July 12, 2019 01:28 PM UTC

Hide All the time,

public class MyEntity
{
     public int ID {get;set;}
     public string Name {get;set;}
     public string CellPhoneNo {get;set;}
}


@(Html.EJS().Grid("TestGrid").DataSource(Model.Report).Render()


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 15, 2019 09:09 AM UTC

Hi Fred,  

Thanks for the update.  

By default, if the Grid has not been given any columns, the columns will be auto-generated in the client-end. So, the Annotation properties will not be applied to the Grid. So, we suggest to hide the required columns in the client-end in the DataBound event of the Grid. Refer to the following code example. 

 
@Html.EJS().Grid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.dataSource).DataBound("onBound").  
AllowPaging().PageSettings(page=>page.PageCount(5)).Render() 
 
<script> 
    function onBound(args) { 
        this.getColumns()[1].visible = false; 
        this.refresh(); 
    } 
</script> 

Regards,  
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon