I am working in an MVC 3.0 application. In my project I used Telerk mvc grid for data listing. I made grid edit model as "InCell" and provided key board navigation in my question answer area. Each question will have 2 answer options such as "Facts" and "Actions" and will be numeric value. I have used "integer" editor template for this purpose. My requirement is that when the user presses tab key from "Facts" integer textbook, focus will move it to "Actions" integer textbox and if the user presses tab from "Actions" it will move to next row "Facts" text box. But currently key board navigation goes through all cells in the grid. There are few columns between "Facts" and "Actions". My code for grid listing looks like.
#(Html.Telerik().Grid<AnswerQuestionVM>()
.Name("GridQuestions")
.DataKeys(keys =>
{
keys.Add(p => p.QuestionID);
})
.Columns(columns =>
{
columns.Bound(p => p.QuestionNumber).Format("{0:0.00}").HtmlAttributes(new { style = "text-align:center;" }).Title("#").Width("5%").ReadOnly();
columns.Bound(p => p.QuestionName).Title("Question Name").Width("43%").ReadOnly();
columns.Bound(p => p.Facts).Width("8%");
columns.Template(#<text></text>).ClientTemplate("<img src='" + #Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=FactOptions#>' />");
columns.Bound(p => p.Actions).Width("8%");
columns.Template(#<text></text>).Width("2%").ClientTemplate("<img src='" + #Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=ActionOptions#>' />");
columns.Template(#<text></text>).Title("Skip").Width("3%").ClientTemplate(
"<# if(Skip==false) {#>" +
"<input type='checkbox' style='cursor:pointer;' class='skipClass' />" +
"<#} else{#>" +
"<input type='checkbox' style='cursor:pointer;' class='skipClass' checked='checked' />" +
"<# } #>"
);
columns.Bound(p => p.Note).Title("Note").Width("26%");
})
.Editable(editing => editing.Mode(Telerik.Web.Mvc.UI.GridEditMode.InCell))
.KeyboardNavigation( navigation => navigation.EditOnTab(true))
.ClientEvents(e => e.OnSave("OnSave"))
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("GetQuestion", "AnswerQuestion", new { Area = "question", ajax = true }).Enabled(true);
})
.Scrollable(scrolling => scrolling.Enabled(false))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(false))
.Footer(true)
)
Code for Integer editor template for "Facts" & "Actions" columns bellow.
#(Html.Telerik().IntegerTextBox()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
.InputHtmlAttributes(new { style = "width:100%", pattern = "[0-9]*" })
.MinValue(1)
.MaxValue(5)
.Value(Model)
)
Please provide a solution. Any help is appreciated.
Here is what I can suggest you as a work-around because your goal is not supported out of the box.
Feel free to optimize/change the implementation or to make it more generic (e.g. use classes to find cells and not to rely on indexes)
$(function () {
$('#persons tbody').on('keydown', function (e) {
if (e.keyCode == 9) {
var currentCell = $(e.target).closest('td');
var cellIndex = currentCell.index();
if (cellIndex == 2 || cellIndex == 4) { //if editing cell in third or fifth column, use different indexes if needed
e.stopPropagation();
e.preventDefault();
var grid = $('#persons').data().kendoGrid;
if (cellIndex == 2) {
var cellToEdit = currentCell.parent().find('td:eq(4)');
grid._handleEditing(currentCell, cellToEdit);
}
if (cellIndex == 4) {
var cellToEdit = currentCell.parent().find('td:eq(2)');
grid._handleEditing(currentCell, cellToEdit);
}
setTimeout(function () {
cellToEdit.find('input').focus();
})
}
}
})
})
I´m not really sure how to do this, but have you tried using something like tabindex, perhaps by using it within the htmlAttributes? Anyway, I have never done anything like this but maybe you can try something in that area:
columns.Bound(p => p.Facts).Width("8%").HtmlAttributes(new { tabindex = 1 });
columns.Bound(p => p.Actions).Title("Practice").Width("8%").HtmlAttributes(new { tabindex = 2 });
Since you are using Telerik Grid, you might have to mix this somehow within each item. Then again, maybe I´m misunderstanding your point (I´ve been known to do that) :)
Related
I am currently able to submit all records on my Kendo Grid back to the controller, but it does not reflect the latest state of the radio button. I dont want to have to click on a cell multiple times, to go into edit mode, nor use an edit button. I want to simply be able to make a radio button selection, click save and have the current state be reflected on my controller.
Razor View
#model IEnumerable<ECM.DAL.ViewModels.Roles.AcctAppUserRoles>
#using ECM.DAL.Infrastructure.Managers
#using GridEditMode = Kendo.Mvc.UI.GridEditMode
#{
ViewBag.applicationType = (int)SystemWideConfiguration.ApplicationTypes.ECM;
ViewBag.acctId = RightsManager.AccountId;
}
#(Html.Kendo().Grid(Model)
.Name("EcmRolesGrid")
.Columns(columns =>
{
columns.Bound(x => x.IsActive).Width(46)
.ClientTemplate("<input type='radio' name='isActive' value='#= IsActive #' # if (IsActive) { # checked='checked' # } # />")
.Title("Select Role")
.HtmlAttributes(new {style = "text-align:center"});
columns.Bound(r => r.RoleName).Width(75);
columns.Bound(r => r.RoleDescription).Width(125);
})
.HtmlAttributes(new { style = "height:340px;" })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model => model.Id(p => p.UserId))
.Read(read => read.Action("GetApplicationAndAccountRoles", "User", new { applicationType = ViewBag.applicationType, acctId = ViewBag.acctId, userId = ViewBag.EcmRoleUserId.ToString() }))
.Update(update => update.Action("SaveApplicationRoles", "User")))
)
Controller:
[AcceptVerbs(HttpVerbs.Post)]
[HandleAjaxReturnableException]
public void SaveApplicationRoles(IEnumerable<AcctAppUserRoles> updatedRoles)
{
var userRoleDal = new UserRoleDal();
var roleDal = new RoleDal();
var applicationId = Guid.Empty;
var userId = Guid.Empty;
if (updatedRoles != null)
...
Javascript (I am using this because I have several tabs in this view with several grids)
function EcmRolesGridHasChanges() {
$.ajax({
url: 'user/SaveApplicationRoles',
cache: false,
type: 'POST',
contentType: 'application/json;',
charset:'utf-8',
data: JSON.stringify($("#EcmRolesGrid").data().kendoGrid._data)
});
}
Let me give you a visual as well....
When the grid is initially loaded the "Order Entry" Role is selected.
(Not showed)
I'll now choose "Limited User"
When I click save this is what I get on the controller:
I was expecting the first one to be false, second true and third false.
Any ideas?
Thank you.
You need to set the model on radio button click to let the grid know that particular row has been set as dirty therefore fire update event with updated model values
so add this on radio button click..
***************************Grid*******************
columns.Bound(x => x.IsActive).Width(46)
.ClientTemplate("<input type='radio' name='isActive' value='#= IsActive #' # if (IsActive) { # checked='checked' # } # onclick='radioBoxClick(this)' />")
**********************Script********************
//checkbox click function
function radioBoxClick(e) {
grid = $("kendoGrid").data().kendoGrid;
var dataItem = grid.dataItem($(e).closest('tr'));
var model = grid.dataSource.get(dataItem.UserId);
model.set("isActive", e.checked ? 1 : 0);
}
Minor modification to the answer that Shaz and Jayesh Goyani provided.
The function below goes over the other radio buttons and sets it to false.
function radioBoxClick(e) {
var grid = $("#EcmRolesGrid").data().kendoGrid;
var elementCount = grid.dataSource._data.length;
var dataItem = grid.dataItem($(e).closest('tr'));
var model = grid.dataSource.get(dataItem.RoleId);
model.set("IsActive", e.checked ? 1 : 0);
for (var i = 0; i < elementCount; i++) {
var elem = grid.dataSource._data[i];
if (elem.RoleId != model.RoleId)
elem.set("IsActive", 0);
}
}
I am using Kendo() grid in my application which has binding with an model.
I want to provide Upload control in Grid against each row. Please see razor view design as follows
#(Html.Kendo().Grid<Model>()
.Name("Grid")
.Columns(col =>
{
col.Template(#<text></text>).ClientTemplate("<a Title='Export' href='" + Url.Action("Export", "RouteFileExport", new { Id = "#= RouteScheduleID #", routeID = "#= RouteID #" }) + "'><img src=" + #Url.Content("~/Content/images/download.png") + "></a>").Title("Export");
col.Template(#<text>#(Html.Kendo().Upload()
.Name("attachments<#= ID #>")
.HtmlAttributes(new { id = "attachments<#= ID #>" })
.Multiple(false)
.Async(async => async
.Save("Save", "Controller", new { folder = "<#= ID #>" })
.AutoUpload(true)
)
)</text>).Title("Import");
col.Command(command =>
{
command.Destroy();
command.Custom("Unlock");
command.Custom("Notification");
}
);
})
With above design i am not able to get the upload control displayed inside grid. Its displaying BLANK column.
Please let me know how can i achieve upload against each kendo grid row.
Thanks
Are you looking for a custom button in the last column? If you use the custom command buttons it can be linked to JQuery or a controller action like below:
columns.Command(cmd => cmd.Custom("Upload").Text("Upload").Click("UploadJqueryScript")).Width(75);
columns.Command(cmd => cmd.Custom("Upload").Action("UploadMethod", "Controller")).Width(75);
Have you tried these options?
I have been looking all over for the answer and think I am missing something simple. I have a kendo grid where I want one of the columns to be a link to another page with the id as a route parameter. However, the value in the column cells are the bound values and are unchanged by my template. Any insights to this will be appreciated.
#(Html.Kendo().Grid((IEnumerable<ProviderAccess>)Model.Providers)
.Name("grants-grid")
.Columns(columns =>
{
columns.Bound(a => a.ProviderName);
columns.Bound(a => a.HasAccess);
columns.Bound(a => a.ProviderId).ClientTemplate("#= toggleLink(data) #");
})
.Scrollable()
)
<script>
function toggleLink(access) {
var action = '#Url.Action("Toggle", "Access")';
var html = kendo.format("<a href='{0}/{1}'>Toggle...</a>",
action,
access.ProviderId
);
return html;
}
</script>
ClientTemplate isn't using when Kendo Grid is binded to a dataSource on server side like your code.
You should use Template method of columns like below
columns.Template(p => "<a href='..../Toggle/Access/" + p.ProviderId + "'>Click</a>");
dataSource.Server() will let you use a custom.template
dataSource.Ajax() will let you use ClientTemplate
Figuring that out was really frustrating... They are not interchangeable one of the other will work depending on ajax or Server
<%: Html.Kendo().Grid((List<RadCarePlus.V2.Web.Models.GetMeSomeData>) ViewData["Mydata"])
.Name("Grid")
.Columns(columns =>
{
columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>").Title("Testing").Width(140);
//columns.Bound(c => c.EpisodeID).Width(140);
columns.Bound(c => c.AuthStatus).Width(190);
columns.Bound(c => c.CPTCode).Width(100);
columns.Bound(c => c.inscarrier).Width(110);
columns.Bound(c => c.CreatedOn).Width(160);
//columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>");
//columns.Template(c => c.EpisodeID).Title("Testing").ClientTemplate("<a href='ImplementationDetails?EpisodeID=#= EpisodeID#'>#= EpisodeID #</a>");
})
.Pageable(pageable=> pageable.ButtonCount(5))
.Sortable(sortable => sortable.AllowUnsort(false))
.DataSource(dataSource => dataSource.Server().PageSize(5)
)
%>
I am working in an MVC 3.0 application. In my project I used Telerk mvc grid for data listing. I made grid edit mode as "InCell". In my grid, there are two columns "Facts" & "Actions". When I press "Facts" column it changed into edit mode with textbox. Also in Ipad, keypad get displayed automatically. There after when I press "Actions" column, it changed into edit mode but Ipad keypad hides. If I am pressing same "Actions" column or any other column again, Ipad keypad get displayed. But in the online demo of telerik mvc grid batch editing (http://demos.telerik.com/aspnet-mvc/razor/grid/editingbatch) it seems working. I am using telerik version 2012.2.607 in my project. My code for grid listing looks like.
#(Html.Telerik().Grid<AnswerQuestionVM>()
.Name("GridQuestions")
.DataKeys(keys =>
{
keys.Add(p => p.QuestionID);
})
.Columns(columns =>
{
columns.Bound(p => p.QuestionNumber).Format("{0:0.00}").HtmlAttributes(new { style = "text-align:center;" }).Title("#").Width("5%").ReadOnly();
columns.Bound(p => p.QuestionName).Title("Question Name").Width("43%").ReadOnly();
columns.Bound(p => p.Facts).Width("8%");
columns.Template(#<text></text>).ClientTemplate("<img src='" + #Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=FactOptions#>' />");
columns.Bound(p => p.Actions).Width("8%");
columns.Template(#<text></text>).Width("2%").ClientTemplate("<img src='" + #Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=ActionOptions#>' />");
columns.Template(#<text></text>).Title("Skip").Width("3%").ClientTemplate(
"<# if(Skip==false) {#>" +
"<input type='checkbox' style='cursor:pointer;' class='skipClass' />" +
"<#} else{#>" +
"<input type='checkbox' style='cursor:pointer;' class='skipClass' checked='checked' />" +
"<# } #>"
);
columns.Bound(p => p.Note).Title("Note").Width("26%");
})
.Editable(editing => editing.Mode(Telerik.Web.Mvc.UI.GridEditMode.InCell))
.KeyboardNavigation( navigation => navigation.EditOnTab(true))
.ClientEvents(e => e.OnSave("OnSave"))
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("GetQuestion", "AnswerQuestion", new { Area = "question", ajax = true }).Enabled(true);
})
.Scrollable(scrolling => scrolling.Enabled(false))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(false))
.Footer(true)
)
Please tell what I am missing in my code. Any help will be appreciated.
I am working on asp.net mvc. I am trying to display list of messages in a Kendo mvc ui grid.
I have written the code like,
Html.Kendo().Grid((List<messages>)ViewBag.Messages))
.Name("grdIndox")
.Sortable(m => m.Enabled(true).SortMode(GridSortMode.MultipleColumn))
.HtmlAttributes(new { style = "" })
.Columns(
col =>
{
col.Bound(o => o.RecNo).HtmlAttributes(new { style = "display:none" }).Title("").HeaderHtmlAttributes(new { style = "display:none" });
col.Bound(o => o.NoteDate).Title("Date").Format("{0:MMM d, yyyy}");
col.Bound(o => o.PatName).Title("Patient");
col.Bound(o => o.NoteType).Title("Type");
col.Bound(o => o.Subject);
}
)
.Pageable()
.Selectable(sel => sel.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.DataSource(
ds => ds.Ajax().ServerOperation(false).Model(m => m.Id(modelid => modelid.RecNo))
.PageSize(10)
//.Read(read => read.Action("Messages_Read", "Msg"))
)
.Events(ev => ev.Change("onSelectingGirdRow"))
)
and i have the field in the table like IsRead-boolean type. so if the message is unread message then i need to format that record with bold font. I have used clientTemplates but with that i am able to format only particular cells i want format entire row. Please guide me.
as Sanja suggested you can use the dataBound event but it will be better to cycle through the tr elements (the rows). Also I assume that you will need the related dataItem to check if the property that indicates if the message is read.
e.g.
dataBound: function ()
{
var grid = this;
grid.tbody.find('>tr').each(function(){
var dataItem = grid.dataItem(this);
if(!dataItem.IsMessageRead)
{
$(this).addClass('someBoldClass');
}
})
}
You can use dataBound event to change your rows.
dataBound: function ()
{
$('td').each(function(){
if(some condition...)
{
$(this).addClass('someBoldClass')}
}
})
}
There is another way to do that.It's called RowAction.
.RowAction(row =>
{
if (condition)
{
row.HtmlAttributes["class"] = "someBoldClass";
}
})
Please note that the RowAction is available only for rows that are rendered on server side. So in your case, you can use RowAction as an alternative to DataBound.