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).
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.
$("#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.
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).
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>
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");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With