Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Set width of Column conditionally
posted

Hello there,

I'm trying to set the width of a column on a Grid conditionally but struggling with binding on the events to do so.

Context: Razor views/MVC 5

The condition is a property on the c# Model on the page. i.e. Model.ShowColumn.

This is the setup of the grid.

@(Html.Infragistics().Grid<AddressGridRowViewModel>()
    .ID(Model.GridId)
    .Defaults()
    .Render()
)

I've tried a few things to bind onto this and then set the width of the column to 0 (i.e. not show it) but with no luck.

Method 1

$('#@Model.GridId').on("iggridrendering", function (evt, ui) {
var message = "iggridrendering";
console.log(message);
debugger;
});

Method 2

$('#@Model.GridId').igGrid({
rendered: function (evt, ui) {
var isProductionSite = '@Model.IsProductionSite' == '@true';
if (isProductionSite) {
debugger;

var cols = $('#@Model.GridId').igGrid("option", "columns");

var addressTypeColumn = _.findWhere(cols, { key: "AddressType" });
addressTypeColumn.width = 0;
}
}
});

Please advise.