3

I'm using Infragistics on an Entity Framework code-first MVC project. I want to display a table with a hidden column (the ID) and it has to be editable. Here is what I've got so far:

<table id="igTests"></table>
@(Html.Infragistics().Grid<BusinessModel.VO.TestVO>().ID("igTests")
    .AutoGenerateColumns(false)
    .Columns(column =>
    {
        column.For(x => x.TestId).DataType("int").HeaderText("id");
        column.For(x => x.TestNum).DataType("int").HeaderText("Test num");
        column.For(x => x.Type).DataType("string").HeaderText("Type");
        column.For(x => x.Nature).DataType("string").HeaderText("Nature");
        column.For(x => x.TeamName).DataType("string").HeaderText("Team");
        column.For(x => x.CreateDate).DataType("date").HeaderText("Creation date");
    })
    .Features(feature => {
        feature.Sorting().CaseSensitive(true);
        feature.Filtering().Mode(FilterMode.Simple);
    })
    .PrimaryKey("TestId")
    .DataSource(Model.TestsVO.AsQueryable())
    .DataBind()
    .Render())

This is what is displayed:

Now lets add the update feature (i know the readOnly is useless since we are not supposed to see it):

feature.Updating().EnableAddRow(true).EnableDeleteRow(true).EditMode(GridEditMode.Row).ColumnSettings(settings =>
            settings.ColumnSetting().ColumnKey("TestId").ReadOnly(true)
        );

And hide my ID-column:

column.For(x => x.TestId).DataType("int").HeaderText("id").Hidden(true);

Here is what i get. As you can see the table acts like my ID-column was visible.

This happened when I added the update feature. Do you have any idea on how I could fix the "Add new row" row acting like my column was visible? Thanks in advance.

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
Titouan D.
  • 476
  • 6
  • 16

2 Answers2

4

Probably you should add this

}).Features(features => features.Hiding()
           .ColumnSettings(settings =>
           {
                 settings.ColumnSetting().ColumnKey("id").Hidden(true).AllowHiding(false)

http://www.infragistics.com/products/jquery/sample/grid/column-hiding-on-initialization

Titouan D.
  • 476
  • 6
  • 16
Steve
  • 213,761
  • 22
  • 232
  • 286
  • I tryied this also, the problem is that the user can toggle the column if he wants, and I don't want him to. – Titouan D. Nov 08 '12 at 13:27
  • Strange, in the example linked above they say `This sample demonstrates how columns are hidden during grid initialization. In this example, “Product Name” and “List Price” columns are hidden in the grid and have allowHiding set to false. Note: When hiding columns during initialization, column indicators are not shown, so hidden columns cannot be made visible by the user.` – Steve Nov 08 '12 at 13:32
  • Adding `.AllowHiding(false)` solved the problem. I edited your answer :) – Titouan D. Nov 08 '12 at 14:18
  • Thanks, probably that part of the code is still in the clipboard :-) – Steve Nov 08 '12 at 14:26
0

I got it to work using .Width("0px") and ReadOnly on my ID-column. A bit dirty but had no other choice...

Titouan D.
  • 476
  • 6
  • 16