[英]Populating a Tooltip with a Partial View - In a Telerik MVC Grid
I currently have a Telerik MVC Grid that is populated with Patients. 我目前有一个填充有患者的Telerik MVC网格。 What I am trying to accomplish is whenever the row is clicked on, a tooltip will be presented displaying additional details of the Patient. 我要完成的工作是,每当单击该行时,都会显示一个工具提示,显示患者的其他详细信息。
The Grid 网格
<% Html.Telerik()
.Grid<Mvc2.ViewModels.PatientsGridViewModel>()
.Name("PatientsGrid")
.Columns(columns =>
{
columns.Bound(o => o.PatientId).ClientTemplate("<input class='gridcheck' type='checkbox' name='checkedRecords' value='<#=PatientId#>'/>").Width(30).Title("");
columns.Bound(o => o.PatientGuid).Title("Patient Id");
columns.Bound(o => o.PatientName).Title("Patient Name");
columns.Bound(o => o.DateOfBirth).Title("Date of Birth?");
columns.Bound(o => o.Sex).Title("Sex");
columns.Bound(o => o.Status).Title("Status");
columns.Bound(o => o.LastActivityDate).Title("Last Activity");
})
.DataBinding(dataBinding => dataBinding
.Ajax()
.Select("_AjaxBindingPatients", "Patients")
)
.Sortable()
.ClientEvents(events => events.OnDataBound("onDataBound").OnRowSelect("onRowSelect"))
.Pageable()
.Selectable()
.Render();
%>
The Row Clicked Event (which will need to fire the Tooltip) 行点击事件 (需要触发工具提示)
function onRowSelect(e) {
var row = e.row;
$.ajax({ type: "POST",
url: "/Patients/GetAdditionalPatientInformation",
datatype: "json",
traditional: true,
data:
{
'patientGuid': row.cells[1].innerHTML
}
});
}
and finally the Controller Action (which would return a Patient using the patientGuid) 最后是Controller Action (它将使用PatientGuid返回Patient)
[HttpPost]
public Patient GetAdditionalPatientInformation(string patientGuid)
{
Patient currentPatient = currentPatients.Where<Patient>(p => p.PatientGuid == Guid.Parse(patientGuid)).FirstOrDefault();
return currentPatient;
}
Currently - the onRowSelect fires properly and calls the controller, which gets the correct Patient. 当前-onRowSelect会正确触发并调用控制器,以获取正确的Patient。 I am just trying to figure out a simple tooltip to use to implement this - or if any other more elegant ways are avaiable. 我只是想找出一个简单的工具提示来实现此目的-或是否有其他更优雅的方法可用。
Thanks greatly, If you need any elaborations - just ask. 非常感谢,如果您需要任何细节-请问一下。
Finally found a solution to this issue - as I could not find a plug-in that could solve this issue. 终于找到了解决此问题的方法-因为我找不到可以解决此问题的插件。
I created my own div that would be hidden (and act as the tool-tip) and then I simply changed my onRowSelect() function to call my Partial View and populate the div, as shown : 我创建了自己的将被隐藏的div(并用作工具提示),然后我仅更改了onRowSelect()函数以调用Partial View并填充div,如下所示:
var row = e.row;
var height = this.offsetTop;
var width = (this.offsetWidth / 2) - 300;
$.post("/Patients/GetAdditionalPatientInformation", { 'patientGuid': row.cells[1].innerHTML }, function (data) {
$("#tooltip").html(data);
$("#tooltip").css("left", width);
$("#tooltip").css("top", height + 55);
$("#tooltip").show();
});
The height and width are used to center the pop-up below the selected row in the grid. 高度和宽度用于使弹出窗口居中于网格中所选行的下方。 I hope that this helps someone if they run into any issues that are similar. 我希望这对某人遇到类似问题有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.