0

I have two columns that I will like to hide in a webgrid. This webgrid resides in a partial view. Here are the columns below

    gridColumns.Add(grid.Column("PaymentAmount", header: T("Payment<br/>Amount"), canSort: false, format: item => Html.TextBox("PaymentAmount", (object)string.Format("{0:#,0.00}", item.AmountDue))));
    gridColumns.Add(grid.Column("ExpText", header: T("Explanation"), canSort: false, format: item => Html.TextBox("ExpText", "")));

Here is my attempt with jquery below

    function hidecolumns(column) {
            $('td:nth-child(' + column + '),th:nth-child( ' + column + ')').hide();        
        }

This does not work. Kindly assist.

tereško
  • 58,060
  • 25
  • 98
  • 150
Baba
  • 2,059
  • 8
  • 48
  • 81
  • Why don't you simply leave the columns out of the grid? (e.g. don't include the gridColumns.Add for those two columns). – Splendor Nov 14 '13 at 20:41
  • I will like to use the columns later. I want to be able to turn it on and off – Baba Nov 14 '13 at 20:47

1 Answers1

1

You can use a datatable, if thats ok. It makes things way easier and better looking.

Just add this in your script:

$('#GridID').DataTable({
    "columnDefs": [
        {
            "targets": [0],
            "visible": false,
            "searchable": false
        }
    ]
});

You will be able to use the column later too.

Ardis thrash
  • 164
  • 9