Kendo UI for MVC Grid How do I hide the ID column

笑着哭i 提交于 2019-12-10 15:53:22

问题


I would like to hide the ID column of a Kendo grid but still be able to reference it for other actions. I tried making the Width = 0 but that only makes it really wide.

@(Html.Kendo().Grid(Model)
        .Name("LineItems")
        .Columns(columns =>
            {
                columns.Bound(o => o.ID).Width(1);
                columns.Bound(o => o.Ui).Width(20);
                columns.Bound(o => o.QtyOrdered).Width(20);
                columns.Bound(o => o.Nomenclature).Width(200);
                columns.Bound(o => o.QtyShipped).Width(140);
                columns.Bound(o => o.QtyReceived).Width(200);
                columns.Bound(o => o.Hazmat).Width(50);

            })

Edit on June 26

OK I was able to get a reasonable solution based on a post from the Kendo forum. As long as the ID is defined in the datasource, the column does not have to be defined in the grid. You still have access to the ID value. I wrote a quick snippet to prove it and it returns the ID without the ID column in the grid.

<script>
  $(document).ready(function () {
      $("#btn").on("click", function () {

          var grid = $("#LineItems").data("kendoGrid");
          var data = grid.dataSource.data();
          $.each(data, function (i, item) {
              alert(item.ID);
           });
      });
  });
</script>

回答1:


Hidden columns are supported since the Q2 2012 release. You can now use the Hidden() setting.




回答2:


You can make the column hidden via the Hidden() method. Is this okey for you?




回答3:


It looks like in the current version its not supported, they do have a page where you can vote to get this feature added to Kendo. They may have started working on it since the status does say 'started' about 13 hours ago.

http://kendo.uservoice.com/forums/127393-kendo-ui-feedback/suggestions/2804580-ability-to-show-hide-columns-in-grid

In the meantime it looks like some users might have some suggestions in this post by setting the style of that column to display:none http://www.kendoui.com/forums/ui/grid/hide-columns-in-grid-kendo.aspx



来源:https://stackoverflow.com/questions/11210989/kendo-ui-for-mvc-grid-how-do-i-hide-the-id-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!