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

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

Thread ID:

Created:

Updated:

Platform:

Replies:

145871 Jul 11,2019 03:05 PM UTC Jul 15,2019 09:09 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Grid
Fred Morin
Asked On July 11, 2019 03:05 PM UTC

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



Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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. 


Fred Morin
Replied On 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()

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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. 


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