I have this kendo grid on a asp.net mvc project
<div class="actualGrid" id="actualGrid">
@(Html.Kendo().Grid<AVNO_KPMG.Models.Bench>() //Bench Grid
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.name).Title("Bench").Filterable(ftb => ftb.Cell(cell => cell.Operator("startswith"))).Width(100);
columns.Bound(p => p.freeSeats).Title("Free Seats").Width(200).Filterable(ftb => ftb.Cell(cell => cell.Operator("gte"))).HtmlAttributes(new { @class = "FreeSeats" })
.ClientTemplate("<div class='barthingy'><div class='bars_text'><div class='seatsText'><span class=\"bookfull\"></span> <b>#=bookedSeats#</b> USED SEATS</div><div class='seatsText'><span class=\"bookNotfull\"></span> <b>#=freeSeats#</b> TOTAL OF SEATS</div></div><div id='bigbar'><div class='bigbar' style='width:100%; float:left; background-color:rgb(142, 188, 0);'><div ' style='float:right; width:#=bookedSeats *100 / seatsCount#%; background-color:rgb(255, 99, 71); height:16px ' class='b_#=name#' id='temp-log'></div></div></div></div>");
})
.Pageable()
.Sortable()
.Scrollable(scrolling => scrolling.Enabled(false))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Events(events => events.DataBound("onDataBound").FilterMenuInit("filterInit"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.id))
.Read(read => read.Action("GetBenches", "Deskcheckin"))
)
)
</div>
I would like to know if there is a way to prevent the filters to accept negative values ( even if we press the arrow down, when the value is 0). I tried adding this to the inputs of the grid
$(".actualGrid :input").attr("onkeypress", "return event.charCode >= 48 && event.charCode <= 57");
But it only prevents the user typing negative values, he can stil use arrows.
EDIT:
I created this function as sugested bellow
function filterInit(e) {
console.log("FILTER INIT!");
if (e.field == "Free Seats") {
//depends of how many inputs you have per filter
$(e.container.find("input:eq(1)")).kendoNumericTextBox({
min: 0
});
}
}
But still doesnt work :\
I tried doing this with jQuery
$(".actualGrid :input:eq(4)").kendoNumericTextBox({
min: 0
});
Works a little bit better, if i use the arrows from keyboard, it doesnt go bellow 0, but if i click on the arrows on the right side of the input, it still goes to negative numbers