Remove time from MVC Razor Kendo Grid date column - razor

How do i restrict the kendo datetime picker to allow only to select date ?
Currently a clock icon appears next to the Date picker, i don't want that.
The fields which ends with date are my date columns.
All the date fields are nullable date column (i.e DateTime?)
Can anyone point me right direction?
Here is my razor :
#(Html.Kendo().Grid(Model.employeedetailsList)
.Name("DependentGrid")
.Columns(columns =>
{
columns.ForeignKey(p => p.TitleCode, Model.TitleList, "TitleCode", "TitleDescription").Title("Title").Width(130);
columns.Bound(p => p.FirstName).Title("First Name");
columns.Bound(p => p.MiddleName).Title("Middle Name");
columns.Bound(p => p.LastName).Title("Last Name"); ;
columns.ForeignKey(p => p.Gender, Model.GenderList, "TitleCode", "TitleDescription").Title("Gender");
columns.ForeignKey(p => p.RelCode, Model.RelList, "RelCode", "RelName").Title("Rel");
columns.Bound(p => p.DepDOB).Format("{0:dd-MMM-yyyy}").Title("Date of Birth");
columns.Bound(p => p.RelStartDate).Format("{0:dd-MMM-yyyy}").Title("Rel Start Date");
columns.Bound(p => p.RelEndDate).Format("{0:dd-MMM-yyyy}").Title("Rel End Date");
columns.Bound(p => p.EmailAddress).Title("Email");
columns.Bound(p => p.DepPassportNumber).Title("Passport Number");
columns.Bound(p => p.DepPassportExpDate).Format("{0:dd-MMM-yyyy}").Title("Passport Expiry Date");
columns.Bound(p => p.RPNumber);
columns.Bound(p => p.RPIssueDate).Format("{0:dd-MMM-yyyy}").Title("RP Issue Date");
columns.Bound(p => p.RPExpDate).Format("{0:dd-MMM-yyyy}").Title("RP Expiry Dates");
})
.Sortable()
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(m => m.DependantDetialId);
})
.Update(update => update.Action("employeedetails_Update", "Mycontroller")
.Data("additionalData"))
.Create(create => create.Action("employeedetails_Create", "Mycontroller")
.Data("additionalData"))
.Destroy(delete => delete.Action("employeedetails_Destroy", "Mycontroller")
)
.Events(e => e.RequestEnd("DependentGrid_onComplete")
)
)
)

This was far easier, for me. If you're using MVC, in your model, you just tell it to use DataType.Date:
[DataType(DataType.Date)]
public DateTime RelStartDate{ get; set; }
You will need using System.ComponentModel.DataAnnotations; at the top of your page to include these tags.
Source: http://www.telerik.com/forums/remove-time-timepicker-from-grid

What I usually do when I only want the date and not the time is to create an Editor Template for that specific field.
Inside your view folder you create a new folder named EditorTemplates. In your case that might be /Views/Employees/EditorTemplates. Inside that folder you create a file named RelStartDate.cshtml which we'll use to display the DatePicker control.
In the new file you add the following lines:
#model DateTime?
#(Html.Kendo().DatePicker()
.Name("RelStartDate")
.Value(Model == null ? DateTime.Now.Date : ((DateTime)#Model).Date)
)
To use it you just have to write
columns.Bound(p => p.RelStartDate).EditorTemplateName("EmployeeDate");

A la propiedad del modelo tienes que poner una anotaciĆ³n ejemplo:
[UIHint("Date")]// o [DataType(DataType.Date)]
[Display(Name = "Fecha2")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = " {0:MM/dd/yyyy}")]
public DateTime? fecHastaCuentaExenta { get; set; }

Related

Kendo Grid - Not showing certain sub grids

I have a kendo grid within an mvc asp.net core application. When I expand the grid into a sub grid, for the most part, it works as expected, showing the sub grid and then making the call to the controller and returning the json data required.
When I expand the root grid to select a row to expand. On specific rows, when the sub grid is created, the root report is almost collapsed, the columns disappear and all the data rows. Subsequently, the call to the controller is still executed as normal and the data is returned. However, the data is not shown on screen as it appears the sub report is not displayed.
Why would the code that works to generate a sub report for one row, not work for another?
This is repeatable on my setup. i.e - I can refresh and restart my browser/application and the same rows cause this issue.
Clicking the second row causes the report to collapse, as if its datasource and columns were removed.
Please note that the root report I speak of, is in actual fact a sub report.
Root Report:
<script id="SalesByLocDept_DetailTemplate" type="text/x-kendo-tmpl">
<h4>Department Sales Summary For Location: #=LocCode# - #=LocName#</h4>
#(Html.Kendo().TabStrip()
.Name("sales_by_loc_tabstrip_#=ID#")
.Items(items =>
{
items.Add()
.Text("Department Summary")
.Selected(true)
.Content(#<text>
#(Html.Kendo().Grid<SalesSummaryByDepartmentViewModel>()
.Name("sales_by_loc_dept_tabstrip_#=ID#")
.Scrollable()
.Reorderable(r => r.Columns(true))
.Resizable(r => r.Columns(true))
.ColumnMenu()
.Columns(columns =>
{
columns.Bound(f => f.DeptCode).Title("Department Code");
columns.Bound(f => f.DeptDesc).Title("Department Name");
columns.Bound(f => f.TakingsToday).Title("Today's Takings");
columns.Bound(f => f.MarginToday).Title("Today's Margin");
columns.Bound(f => f.TakingsMonth).Title("Month's Takings");
columns.Bound(f => f.MarginMonth).Title("Month's Margin");
columns.Bound(f => f.TakingsYear).Title("Year's Takings");
columns.Bound(f => f.MarginYear).Title("Year's Margin");
columns.Bound(f => f.TakingsToDate).Title("Takings To Date");
columns.Bound(f => f.MarginToDate).Title("Margin To Date");
})
.Pageable(pageable => pageable.Refresh(true).PageSizes(new int[] { 100, 150, 200 }))
.Sortable()
.Selectable()
.Navigatable()
.Filterable()
.ClientDetailTemplateId("SalesByLocDeptGroup_DetailTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => { model.Id(detail => detail.ID); })
.Read(read => read.Action("SalesByLocDepartment_Read", "Reporting", new { LocCode = "#=LocCode#" }))
).ToClientTemplate()
)</text>);
}).ToClientTemplate()
)
</script>
Sub Report:
<script id="SalesByLocDeptGroup_DetailTemplate" type="text/x-kendo-tmpl">
<h4>Group Sales Summary For Location: #=LocCode# - #=LocName#, Department: #=DeptCode# - #=DeptDesc#</h4>
#(Html.Kendo().TabStrip()
.Name("sales_by_loc_dept_tabstrip_#=ID#")
.Items(items =>
{
items.Add()
.Text("Group Summary")
.Selected(true)
.Content(#<text>
#(Html.Kendo().Grid<SalesSummaryByGroupViewModel>()
.Name("sales_by_loc_dept_group_tabstrip_#=ID#")
.Scrollable()
.Reorderable(r => r.Columns(true))
.Resizable(r => r.Columns(true))
.ColumnMenu()
.Columns(columns =>
{
columns.Bound(f => f.GroupCode).Title("Group Code");
columns.Bound(f => f.GroupDesc).Title("Group Name");
columns.Bound(f => f.TakingsToday).Title("Today's Takings");
columns.Bound(f => f.MarginToday).Title("Today's Margin");
columns.Bound(f => f.TakingsMonth).Title("Month's Takings");
columns.Bound(f => f.MarginMonth).Title("Month's Margin");
columns.Bound(f => f.TakingsYear).Title("Year's Takings");
columns.Bound(f => f.MarginYear).Title("Year's Margin");
columns.Bound(f => f.TakingsToDate).Title("Takings To Date");
columns.Bound(f => f.MarginToDate).Title("Margin To Date");
})
.Pageable(pageable => pageable.Refresh(true).PageSizes(new int[] { 100, 150, 200 }))
.Sortable()
.Selectable()
.Navigatable()
.Filterable()
.ClientDetailTemplateId("SalesByLocDeptGroupProduct_DetailTemplate")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => { model.Id(detail => detail.ID); })
.Read(read => read.Action("SalesByLocDeptGroup_Read", "Reporting", new { LocCode = "#=LocCode#", DeptCode = "#=DeptCode#" }))
).ToClientTemplate()
)</text>);
}).ToClientTemplate()
)
</script>
I noticed that the rows which would fail had a pattern.
If I expanded the root report on row 1. The sub report, on expanding it's row 1, would fail.
If I expanded the root report on row 3. The sub report, on expanding it's row 3, would fail.
This made me look into the Name properties of my grids & tabs. I was including an ID on the end as a way of uniquely identifying them. I removed the IDs from the tabs. For the grids I had to further uniquely Identify them, using a combination of model values and Ids.
If anyone understands this behavior further than I do, please comment.

Set initial filter on a boolean field column on load

Telerik Kendo MVC Grid - How do I set onload/initial filter equals True with checkbox columns?
I am trying to set a True/False column filter to True on initial load. My Viewmodel has a bool property called IsHoliday. I have followed the example in the link above but i don't have any records showing in the grid at startup. My read action returns a JSON of IEnumerable as suggested in the referenced link. My View is as follows:
#(Html.Kendo().Grid<HolidayVM>()
.Name("h_grid")
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.ServerOperation(false)
.Events(events => events.Error("grid_error")) // Handle the "error" event
.Model(model =>
{
model.Id(m => m.Date);
model.Field(m => m.Date).Editable(false);
})
.Filter(f => f.Add(m => m.IsHoliday.Equals(true)))
.Read(read => read.Action("Holiday_Read", "Holiday"))
.Update(up => up.Action("Holiday_Update", "Holiday").Data("grid_sendAntiForgery"))
)
.Columns(columns =>
{
columns.Bound(p => p.Date).Width(30).Format("{0:dd-MMMM}");
columns.Bound(p => p.HolidayText).Width(100).Filterable(false);
columns.Bound(p => p.IsHoliday)
.ClientTemplate("<input type='checkbox' #= IsHoliday ? '' : checked='checked' # disabled='disabled' />")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Is equal to")))
.Width(30);
columns.Command(cmd =>
{
cmd.Edit().HtmlAttributes(new { title = "Edit" });
}).Title("Commands").Width(25);
})
.Pageable()
.Sortable()
)
Ideally I will like my grid to look like in attached image, on load, with IsHoliday set to True
I finally figured it out.
.Filter(f => f.Add(m => m.IsHoliday).IsEqualTo(true))
instead of
.Filter(f => f.Add(m => m.IsHoliday.Equals(true)))
use this easily:
columns.Bound(p => p.ISProperty).ClientTemplate("#= ISProperty? 'Yes' : 'No' #")

MVC Telerik grid not binding only displaying json data in browser

I am trying to get a telerik grid to display json data that is being return from a controller action but the only it displays the actual json data in the browser window.
Am i supposed to call .BindTo after read?
Am i doing something wrong in my action?
am i going about this all wrong?
[HttpGet]
public ActionResult ReadLeads([DataSourceRequest]DataSourceRequest request)
{
var model = new RecordLookupViewModel();
using (var db = new RGI_MasterEntities())
{
db.Configuration.ProxyCreationEnabled = false;
var results = db.tblMasterLeads
.Where(
x => (model.FirstName == null || x.FirstName.Equals("Eric"))
&& (model.RecordType == null || x.MasterLeadType.Equals("Responder"))
)
.Select(s => new LookupGridResults
{
FirstName = s.FirstName,
LastName = s.LastName,
City = s.city,
State = s.state,
County = s.county,
Zip = s.zip
}).Take(10);
var result = results.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);
}
}
Hers is my view code for the grid.
#(Html.Kendo().Grid<LookupGridResults>()
.Name("grid")
.AutoBind(false)
.Columns(columns =>
{
columns.Bound(p => p.FirstName).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains"))).Width(225);
columns.Bound(p => p.LastName).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.City).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.County).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.State).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(p => p.Zip).Width(225).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(true)
.Read(read => read.Action("ReadLeads", "LeadsManagement").Type(HttpVerbs.Get))
)
)
Here are my results btw.
{"Data":[{"LastName":"COFFEY","FirstName":"EDWARD","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2304"},{"LastName":"DESPAIN","FirstName":"TONY","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-9397"},{"LastName":"HALBIG","FirstName":"RONALD","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-1556"},{"LastName":"KRAUS","FirstName":"REBECCA","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2714"},{"LastName":"LAWLESS","FirstName":"MEREDITH","City":"CAMPBELLSVILLE","County":"TAYLOR","State":"KY","Zip":"42718-1556"},{"LastName":"RANKIN","FirstName":"PAULINE","City":"LAWRENCEBURG","County":"ANDERSON","State":"KY","Zip":"40342-1374"},{"LastName":"SHIRLEY","FirstName":"LORRAINE","City":"CAMPBELLSVLLE","County":"TAYLOR","State":"KY","Zip":"42718-1557"},{"LastName":"STAPLES","FirstName":"DAMON","City":"HODGENVILLE","County":"LARUE","State":"KY","Zip":"42748-1208"},{"LastName":"WILLIAMS","FirstName":"LUCY","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-2308"},{"LastName":"WILSON","FirstName":"BELIDA","City":"FRANKFORT","County":"FRANKLIN","State":"KY","Zip":"40601-1321"}],"Total":10,"AggregateResults":null,"Errors":null}
Thanks for all the help, it seemed i was missing a reference to a bundle. I do credit Mark Schultheiss for pointing me in the right direction.
Got it completly working today. Here is what fixed it.
I changed my actionresult to a JsonResult.
I had filtering turned on in the grid but none of my columns had filtering attributes.
I think thats about it. It works great now.

Kendo Grid Read Action Not Passing Data To Controller Via the .Data Method Call

I have a Kendo Grid (MVC Razor) that I am trying to have pass extra data to the controller via the .Data call off of the Read method:
#(Html.Kendo().Grid<AssignedSiteGridPoco>()
.Name("UnAssignedSiteGrid")
.Filterable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Columns(columns =>
{
columns.Bound(p => p.SiteId).Hidden();
columns.Bound(p => p.SiteName).Title("Site Name").Width(180);
columns.Bound(p => p.City).Title("City").Width(80);
columns.Bound(p => p.StateName).Title("State Name").Width(100);
columns.Command(command => command
.Custom("Add")
.Click("unassignedSiteGridClick")
).Width(90);
})
.Scrollable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Resizable(resize => resize.Columns(true))
.Events(events =>
{
//events.Change("GridChange");
//events.DataBound("OnDataBound");
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.SiteId);
model.Field(p => p.SiteName);
model.Field(p => p.City).Editable(false);
model.Field(p => p.StateName).Editable(false);
})
.PageSize(15)
.Read(read => read.Action("GetUnassignedSiteGridDataList", "Manager").Data("getUserRightName"))
))
The Javascript block, placed above the grid div, is as follows:
function getUserRightName() {
return
{
UserRightName : "2"
};
}
And the controller:
public JsonResult GetUnassignedSiteGridDataList([DataSourceRequest]DataSourceRequest request, string UserRightName)
{
var model = new AssignedSiteGridPoco();
var siteList = _managerPresentationService.GetUnassignedSiteGridDataList(model);
return Json(siteList.ToDataSourceResult(request));
}
The string value being passed from the view's read method is null in the "UserRightName" string. According to the examples, it should pass back the text value "2" My Version of Kendo is: 2014.2.807 InternalBuild. Is there a problem in this build in this area?
Thanks,
Steven
Wrap the key name in the json structure into quotes i.e.
change your js function to this:
function getUserRightName() {
return {'UserRightName':"2"};
}

Multiple Kendo UI Grid with dropdown editor templates edit issues in ASP.NET MVC razor page

I have two Kendo UI grids with drop down editor template columns in an ASP.NET MVC razor page.Both grids are having one row always and working fine with edit and update.
But when the user clicks one first grid edit and trying to click the second grid edit then the editor templates are not working for the second grid. it is showing the grid values within a textbox. Both grids are sharing same editor templates for the columns. No errors in the browser console.
I tried moving these grids in partial views and try to create different editor templates for each grid but always the result is the same.
The funny thing is that if you edit in the second grid first and then click the first grid edit it doesn't create any problem and shows all the dropdown values with editor templates. (first and second grid means from top to bottom)
both grids have different models but share the same class for the model.
I am giving the sample code here ..please help me ..already spent lot of time on this.
#model ProjectName.ViewModel.EmployeesViewModel
#(Html.Kendo().Grid(Model.CasualEmployees)
.Name("GridCasualEmployees")
.Columns(columns =>
{
columns.Bound(i => i.Frequency).Title("Frequency").EditorTemplateName("Frequency").ClientTemplate("#:Frequency#").HtmlAttributes(new { #style = "text-align:Left; " }).Width(75);
columns.Bound(i => i.Quarter).Title("Quarter").EditorTemplateName("Quarter").ClientTemplate("#= kendo.toString(Quarter,\"MMM yyyy\") #").HtmlAttributes(new { #style = "text-align:left; " }).Width(75);
columns.Bound(i => i.EmpId).Hidden();
columns.Command(command => command.Edit()).Width(175);
})
.ToolBar(toolbar => toolbar.Create())
.Editable((editable => editable.Mode(GridEditMode.InLine)))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(s => s.EmpId);
model.Field(s => s.Frequency);
model.Field(s => s.Quarter);
})
.Create(update => update.Action("CreateEmployee", "Employee"))
.Read(read => read.Action("ReadEmployee", "Employee"))
.Update(update => update.Action("UpdateEmployee", "Employee"))
)
)
#(Html.Kendo().Grid(Model.PermanentEmployees)
.Name("GridPermanentEmployees")
.Columns(columns =>
{
columns.Bound(i => i.Frequency).Title("Frequency").EditorTemplateName("Frequency").ClientTemplate("#:Frequency#").HtmlAttributes(new { #style = "text-align:Left; " }).Width(75);
columns.Bound(i => i.Quarter).Title("Quarter").EditorTemplateName("Quarter").ClientTemplate("#= kendo.toString(Quarter,\"MMM yyyy\") #").HtmlAttributes(new { #style = "text-align:left; " }).Width(75);
columns.Bound(i => i.EmpId).Hidden();
columns.Command(command => command.Edit()).Width(175);
})
.ToolBar(toolbar => toolbar.Create())
.Editable((editable => editable.Mode(GridEditMode.InLine)))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(s => s.EmpId);
model.Field(s => s.Frequency);
model.Field(s => s.Quarter);
})
.Create(update => update.Action("CreateEmployee", "Employee"))
.Read(read => read.Action("ReadEmployee", "Employee"))
.Update(update => update.Action("UpdateEmployee", "Employee"))
)
)
#(Html.Kendo().DropDownListFor(i => i)
.Name("Quarter")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable)ViewBag.Quarters)
.OptionLabel("Select Quarter")
)
#(Html.Kendo().DropDownListFor(i => i)
.Name("Frequency")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable)ViewBag.Frequencies)
.OptionLabel("Select Frequency")
)
public class EmployeesViewModel
{
public List<Employee> CasualEmployees{ get; set; }
public List<Employee> PermanentEmployees{ get; set; }
}
Thanks in advance,