I have seen a couple of code examples of how to do this, but none in the format I'm looking for. I tried to convert them myself, but without success. What I'm trying to do is to create a custom row filter that will give you an x-amount of options that can be used on a date.
columns.Bound(cc => cc.StartDate).Width(160)
.HeaderHtmlAttributes(new { title = "startdate") })
.Title("startdate"))
.Filterable(ftb => ftb.Extra(false)
.Operators(op => op.ForDate(d => d
.IsEqualTo("At date")
.IsLessThan("Before date")
.IsGreaterThan("After date"))));
In the code above I'm trying to use filter options so a user can chose to filter events before, at and after a certain date. It would be nice if these options would actualy be shown and even better if a user could use the kendo datepicker.
So my question is: What am I doing wrong that I'm not seeing the correct options and how do i get the date-picker into the filter?
You need to have a column datatype as datetime .
If you're using MVC, in your model, you add DataType.Date above your DatePicker property in case you want only datepicker and not datetimepicker as below:
[DataType(DataType.Date)]
public DateTime StartDate{ get; set; }
Note: add reference to System.ComponentModel.DataAnnotations if its not included in your header.
Then specify in filtrable that UI will be datetime picker
filterable: {
ui: "datetimepicker"
}
OR
columns.Bound(c => c.StartDate).ClientTemplate("#= kendo.toString(kendo.parseDate(StartDate), 'MM/dd/yyyy HH:mm:ss') #")
.Filterable(ftb => ftb.Cell(cell => cell.Template("DateTimeFilter")));
here is a sample code you can refer.In this smple there is column for Birthdate that you can refer.
Demo - sample
In your case it would be like
columns.Bound(cc => cc.StartDate).Width(160)
.HeaderHtmlAttributes(new { title = "startdate") })
.Title("startdate"))
.Filterable(ftb => ftb.Extra(false)
.Cell(cell => cell.Template("DateTimeFilter"))
.Operators(op => op.ForDate(d => d
.IsEqualTo("At date")
.IsLessThan("Before date")
.IsGreaterThan("After date"))));
Hope it helps you.
Related
I'm using a Kendo Grid.
#(Html.Kendo().Grid<Kosten>()
.Name("gridKosten")
.Columns(columns =>
{
columns.Bound(c => c.Costs);
})
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("gridError"))
.Model(model => model.Id(c => c.Id))
.Create(create => create.Action("Kosten_Create", "FahnenSettings"))
.Read(read => read.Action("Kosten_RetrieveAll", "FahnenSettings"))
.Update(update => update.Action("Kosten_Update", "FahnenSettings"))
)
.Editable(editable => editable
.Mode(GridEditMode.InLine)
)
.ToolBar(toolbar => toolbar.Create())
)
Also I set the culture to German.
<script src="https://kendo.cdn.telerik.com/2020.1.219/js/cultures/kendo.culture.de-DE.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2020.1.219/js/messages/kendo.messages.de-DE.min.js"></script>
<script>
$(function () {
kendo.culture("de-DE");
})
</script>
Everything works fine. In my column "Costs" the displayed value is like "1.245,21 €". But when I'm activating the "Edit" function, the value in the input has changed to "1245.21" (check the separator). Do I change the value now to something like "1245.20", the value will become "124.520,00 €".
So if I want to have the correct value, I always have to change back the separator "." to "," manually. My culture is set to German, it shows the german value and it interprete the german spelling with comma correctly after editing. But in the moment I open the inline editing mode, the separator is changing to us format with a dot.
How can I avoid that? Someone has an idea?
The column property is set in the model like
[DataType(DataType.Currency)]
public decimal Costs { get; set; }
For anyone who has the same problem.
I solved it by including the "~\Views\Shared\EditorTemplates" folder. I removed it at the beginning from my solution because I thought these Views were only examples and didn't thought they were actually used. The grid wanted to use the missing "Currency.cshtml" in it.
I have a kendo grid on a page. I added the filtering possibility like this for every column
I need to add the row filtering of the kendo grid, and it looks like this.
#(Html.Kendo().Grid<GGISServices.Models.DistrictViewModel>()
.Name("districtGrid")
.HtmlAttributes(new { #class = "newGrid" })
.Columns(columns =>
{
columns.Bound(c => c.NatureOfProduct).Title(LanguageService.Instance.Translate("NatureOfProduct")).Filterable(f => f.Multi(true).DataSource(ds => ds.Read(r => r.Action("GetFilterData", "Contract", new { Area = GGISWeb.AreaModules.District }).Type(HttpVerbs.Post).Data("{ field: 'NatureOfProduct' }"))));
This filter looks like this, and the user can select more than one item to search
But I needed to change to row filtering mode, because the client asked for search box for every column, so I added
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
and now the filer appears like this
which is ok, this is what the client needs, but they want both searching possibilities, and when I have added the
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
the filter where I can select all items does not appear anymore.
Can you please advise how to do, to show both filter: the searchbox for every column and the other where the user can select the items?
Or if I use only the GridFilterMode.Row the user has the posssibility to select more than one item?
The solution was to add the
.ColumnMenu(f => f.Enabled(true))
and for the columns
.Filterable(f => f.Multi(true));
I have a SQL Table result.
ProductNumber ProductNumberColorClass OrderNumber OrderNumberColorClass
I am trying to use Kendo to render this information. Basically i need the output as
ProductNumber OrderNumber
Data value and Apply Css class( ProductNumberColorClass )
Basically this is a report with a lot of columns. The user can select only the columns that he wants to see.
I am able to render the grid using the examples from the web site. I am not able to apply.
My application is Asp.net mvc application
Update
I will try your feedback. This is my code. Basically i wanted to avoid coding for each column as the list is big around 50 . the report can be customized so the user can hide some columns. .So i used a loop. however in this scenario, the clienttemplate is not work. I am not very sure, if it is a code issue too.
If you can find what is wrong in my code it will help me learn about the issue too.
meanwhileI am going to manually type the columns and add a attribute as visible
#(Html.Kendo().Grid <DataTransferObjects.ViewModels.UserReportDataModel>()
.Name("Grid")
.HtmlAttributes(new { style = "height: 550px;" })
.Pageable(pageable => pageable
.Input(true)
.Numeric(false)
)
.Sortable()
.Scrollable(
scr => scr.Height(430)
)
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetReportData", "ShortTermPlanner").Data("AdditionnalParameters"))
.PageSize(20)
.ServerOperation(false)
)
.Columns(columns =>
{
var colIndex = 0;
foreach (var col in Model.lstHeaderInformation)
{
if (col.SqlColumnName == "ProductNumber")
{
columns.Bound(col.SqlColumnName)
.Title(col.ColumnHeader)
.Filterable(false)
.Visible(col.IsVisible)
.Width(1190)
.ClientTemplate("<div style='background-color:red; text-align:center;width:70px'> #= ProductNumber # </div>");
}
else
{
columns.Bound(col.SqlColumnName)
.Title(col.ColumnHeader)
.Filterable(true)
.Visible(true)
.Width(300)
.Locked(true)
.HtmlAttributes(new { #class = "selectedRow" });
}
}
})
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
)
Update 2 Adding the clienttemplate and specifying the column information worked. Thanks
However i am curious, is there a better way where i can loop through a 3 table which defines the column name, title and class that needed to be displayed and applied to my report.
what i am looking is
MY Report -- Select * from Report
My header table Select colname, title, class from reportcoldefinication
so now for each matching colname from reportcoldefinication
and Report. add a col to the grid with the class applied.
You can use the template functionality for columns in the Kendo grid.
columns.Template(#<div class= '#=ProductNumberColorClass #'> #= ProductNumber#<div/>)
Have implemented one in the example in the below link. Its implemented using JQuery but you can use the razor syntax for kendo for achieving the same.
http://dojo.telerik.com/ukIma/3
I am using Grid.mvc in this link:
https://gridmvc.codeplex.com/
When I use Date filter it shows the calendar but by selecting the date nothing is happening. other kind of filters like text and bool are working fine. I already referench the "Grid.Mvc DatePicker"
This is my code:
#Html.Grid(Model).Columns(columns =>
{
columns.Add(model => model.dataUser).Titled("User").SetWidth(110);
columns.Add(model => model.Create_Date).Titled("Create Date").SetWidth(110).Filterable(true).Format("{0:dd/MM/yyyy}");
columns.Add(model => model.Modified_Date).Titled("Modified Date").SetWidth(110).Filterable(true).Format("{0:dd/MM/yyyy}");
}).WithPaging(20).Sortable().Filterable().WithMultipleFilters()
You may need to convert DateTime property into Date only.
c.Add(x => x.DOB.Date).Titled("Date of Birth").Filterable(true).Sortable(true);
For nullable DateTime it would be tricky, the best is to create additional r/o DateOnly property, and use it.
I have a model like so:
Id Type
-------------
1 Vehicle
2 Trailer
3 Vehicle
I am hoping to eventually use a radio button to control how this data is filtered on a Kendo grid, choosing to filter on whether Type equals Vehicle or Trailer. I don't know how to do that, but, for now, I can't even get the initial filter to work. My grid is as follows:
#(Html.Kendo().Grid<PcKendoUi.Models.CompanyDueDatesIndexVM>()
.Name("DueDates")
.Columns(columns =>
{
columns.Bound(c => c.Id);
columns.Bound(c => c.Type);
})
.Filterable()
.DataSource(ds => ds
.Ajax()
.Model(m => m.Id(x => x.Id))
.Read(s => s.Action("Test", "CompanyDueDates"))
.Filter(filter =>
{
filter.Add(f => f.Type == "Vehicle");
})
)
)
My code is based on the filter example from the documentation.
This still displays all 3 records in the model, rather than just rows 1 and 3. What is also interesting is that after specifying this initial filter, the filter controls also do not allow any filter. That is, they are visible, I can type in data and click Filter, but it will not filter the grid.
Does anyone have an idea what the problem could be?
According the documentation your syntax is not correct, you wrote:
filter.Add(f => f.Type == "Vehicle");
When it should be:
filter.Add(f => f.Type).IsEqualTo("Vehicle");