MutchoUser
MutchoUser

Reputation: 575

How do i hide columns of a kendo grid after a a actionresult

How do i hide columns of a Kendo Grid after an ActionResult I'm using a kendo grid to show some information. In this grid i want to implement a global search with the help of a textbox. Until here all is ok, the search works well and all.

Then I want to hide 1 of my columns, if the column status of the list that populates my grid is false.

how do I achieve this? I tried many approaches but with no success.

My Grid:

@(Html.Kendo().Grid(Model)
          .Name("grid")
          .Events(x => x
                .Edit("onEdit")
                .SaveChanges("SaveChanges")
                .DataBound("DataBound")

          )
          .Columns(columns =>
          {
                  columns.Bound(p => p.ImageUrl).Title("Image");
                  columns.Bound(c => c.Status).Title("status").Hidden(true);
                  columns.Bound(c => c.Name).Title(T("Name"));
                  columns.Bound(c => c.ColumnToHide).Title(T("ColumnToHide"));
                  }
                  )

...

.Read(read => read.Action("GetList",
"GetList").Type(HttpVerbs.Get).Data("selectedFilter"))
                  )

My function in controller:

 public ActionResult GetList([DataSourceRequest] DataSourceRequest request, string valueToSearch)
    {
        var result = this.GetList(valueToSearch).ToList();

        return this.Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

I have tried to hide the columns in the databound but it's not called when the grid is re-populated

thanks in advance

Upvotes: 0

Views: 215

Answers (1)

Rajeshkumar Kandhasamy
Rajeshkumar Kandhasamy

Reputation: 6461

Try this code if helps:

column.Bound(c => c.Status).Title("status").Hidden(true).IncludeInMenu(true);

Upvotes: 0

Related Questions