Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KENDOUI grid in MVC: Is there a way to hide filters on some columns?

Tags:

kendo-ui

I am using a KENDO UI grid in MVC.NET.

The grid is configured to show a column filter for each column.

Some of my columns are not filterable, though, so I want to hide the filter.

Is there a way to configure this from the C# side? (Not using CSS or JS).

like image 720
jm. Avatar asked Jan 08 '13 20:01

jm.


People also ask

How do I turn off the filter on my Kendo grid?

In order to remove the current filters, apply an empty object as a filter to the DataSource. To remove only a specific filter from the Grid DataSource, the filter object needs to be removed from the filters array.

How do I hide column headers in kendo grid?

$("#grid . k-grid-header"). css('display', 'none'); It hides the whole header, and is slightly better than the css solution because it applies the style directly to the header as an inline style, meaning that the style automatically has higher priority over all other kendo styles.

How do I make my Kendo grid editable?

So, if NOC Code=='C01', then COR ABA No. is editable, otherwise it is not. I have achieved this by adding the Edit event on the columns and in that edit handler disabling the HTML input Kendo creates, when no editing is allowed. (In the grid definition, I have Editable(true) to start).


3 Answers

In your code, you probably have something like:

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<%: Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ProductID).Groupable(false);
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.UnitPrice);
        columns.Bound(p => p.UnitsInStock);
    })
    .Groupable()
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Products_Read", "Grid"))
    )
%>
</asp:Content>

If you want ProductID column not being filterable, you should say:

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<%: Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ProductID).Groupable(false).Filterable(false);
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.UnitPrice);
        columns.Bound(p => p.UnitsInStock);
    })
    .Groupable()
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Products_Read", "Grid"))
    )
%>
</asp:Content>
like image 59
OnaBai Avatar answered Sep 29 '22 05:09

OnaBai


If you are not setting up the columns, you could hide the filter buttons after the grid is initialized, such as in the databound event. Here's one way, hiding the filter button on a specific field:

$("#MyGrid").find(".k-header[data-field='Pct_positive']").find(".k-grid-filter").css("visibility","hidden");

To hide them all...

$("#MyGrid").find(".k-header").find(".k-grid-filter").css("visibility","hidden");
like image 23
Troy Avatar answered Oct 02 '22 05:10

Troy


As far as I can tell, you would have to be able to set the columns.filterable configuration property to 'false' for those columns that you don't want filtered, as it defaults to 'true' (see Docs: columns.filterable)

Whether you can do this from the C# side will depend on how the Kendo Grid is being initialised in your code.

like image 30
Chamila Chulatunga Avatar answered Sep 28 '22 05:09

Chamila Chulatunga