-1

I am using @grid.GetHtml gridview to show the grid in my ASP.NET MVC4 application.

I want to visible some columns in my grid view and also i will use these columns for my future functionality.

Please help how to make the columns as visible false in @grid.GetHtml razor grid.

My code

@grid.GetHtml(
    htmlAttributes: new
      {
          id = "XXXX"
      },
    tableStyle: "table table-bordered table-condensed table-hover table-striped",
    headerStyle: "info",
    footerStyle: "webgrid-footer",
    alternatingRowStyle: "webgrid-alternating-row",
    selectedRowStyle: "webgrid-selected-row",
    rowStyle: "gridrow",
    columns: grid.Columns(
        grid.Column("AAAA", "AAA"),
        grid.Column("BBBB", "BBB")
    ) 
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Sup
  • 3
  • 6
  • Please share the code which you are using to initialise your grid – Bassie May 07 '18 at 03:57
  • Possible duplicate of [MVC 3 Webgrid - how do you hide columns you do not want to be visible?](https://stackoverflow.com/questions/7172420/mvc-3-webgrid-how-do-you-hide-columns-you-do-not-want-to-be-visible) – Bassie May 07 '18 at 03:58
  • i dont want the columns to hide as i need these columns for some other operations. So this is not the duplicate of what you have shared. – Sup May 07 '18 at 04:43
  • @grid.GetHtml( htmlAttributes: new { id = "XXXX" }, tableStyle: "table table-bordered table-condensed table-hover table-striped", headerStyle: "info", footerStyle: "webgrid-footer", alternatingRowStyle: "webgrid-alternating-row", selectedRowStyle: "webgrid-selected-row", rowStyle: "gridrow", columns: grid.Columns( grid.Column("AAAA", "AAA"), grid.Column("BBBB", "BBB") ) – Sup May 07 '18 at 04:43
  • So you want your colums to be not visible but not hidden? Please clarify what you mean by that. – Bassie May 07 '18 at 04:44
  • Thank you. I want my columns to be hidden means visible false so that i should able to get the columns data using JQuery function. – Sup May 07 '18 at 04:47

1 Answers1

0

Try adding the columns you wish to hide with

grid.Column("BBBB", "BBB",  style:"hidecol")

Then write some css

.hidecol {
    display: none;
}

If you wish to hide that column header as well, then you can use some JQuery like this

$(document).ready(function() {
    $("#yourGridId th:nth-child(2)").hide();
}

Where you need to replace #yourGrid with an identifier for your grid. This will hide the header above the 2nd column.

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • Thank you. I want my columns to be hidden means to make visible false but i should able to get the columns data using JQuery function. If i use code to hide my columns what you have mentioned then i will not able to get my columns in my JQuery functions. – Sup May 07 '18 at 04:58
  • @Sup I think you can still access it. Have you actually tried it? – Bassie May 07 '18 at 04:59
  • Thank you Bassie for quick reply. I am able to get the my hidden column data. Please help me how to hide the table header as well. I am using your code and able to hide the column data but its not hiding the column header. Please help. – Sup May 07 '18 at 05:11
  • Hi Bassie...Hope you are doing great...Its working as expected. But i am facing one more issue because of this. My grid is by de fault sort is woking before to this change. After changing this My Grid is not working.... – Sup May 09 '18 at 06:15
  • Web Grid Sort is not working as per changes suggested by you. grid.Column("AAAA", "AAAA",style:"hidecol"), Web Grid Sort is working if i use the below type of code. BUt in this web grid will show one extra empty column. Please help. Thanks in Advance. grid.Column(format: @), – Sup May 09 '18 at 06:17
  • @Sup You need to provide all the details for people to be able to help - its probably best if you open a new question as it is a new issue. Post all the relevant code and explain in what way it is not working – Bassie May 09 '18 at 06:38
  • Update the same. But not getting any response. Please Help... URL: https://stackoverflow.com/questions/50247231/webgrid-default-sort-is-not-working-while-using-webgrid-helper-with-column-pr – Sup May 10 '18 at 04:03