Reputation: 81
Can anybody tell me if there is a way to position the edit-form Popup for an mvc grid to align to the center of the screen?
Upvotes: 2
Views: 8179
Reputation: 110
@(Html.Telerik().Grid()
.Name("FormFildGrid")
.ClientEvents(events => events.OnEdit("Grid_onEdit"))
)
function Grid_onEdit(e) {
var popup = $("#" + e.currentTarget.id + "PopUp");
var popupDataWin = popup.data("tWindow");
var l = ($(window).width() / 2 - $(popup).width() / 2);
popup.css({ "left": l + "px", "margin-left": "0", "width": $(popup).width() });
}
Upvotes: 0
Reputation: 81
My friend found out the easiest way of doing by using one of the unexposed inbuilt function of telerik grid
var popup = $("#" + e.currentTarget.id + "PopUp");
//get the data window contained by the popup
var popupDataWin = popup.data("tWindow");
//change popup title by calling the title
popupDataWin.title("Custom Title");
//center the window by calling the method center
popupDataWin.center();
put this piece of code in client side on_edit api of the grid and you will see the magic
Upvotes: 3
Reputation: 81
thanks guys for the valid answers. I know we can position a custom popup window but not for built in edit mode windows.
However I manipulated the position with jquery on the client side on_edit API of telerik grid.
var popup = $("#" + e.currentTarget.id + "PopUp");
popup.css({ "left": ($(window).width()/2 - $(popup).width()/2) + "px", "top": ($(window).height()/2 - $(popup).height()/2) + "px" });
e.currentTarget.id gives the gridname.
Upvotes: 3
Reputation: 974
I have done this before using a custom popup using a separately defined Telerik Mvc Window. My sample code looked like this:
<%= Html.Telerik().Window()
.Name("CompanyWindow")
.Title("Company Details")
.Buttons(b => b.Maximize().Close())
.Visible(false)
.Modal(true)
.Width(600)
.Height(600)
.Draggable(true)
.Resizable()
%>
<% Html.Telerik().Grid<Vigilaris.Booking.Services.CompanySummaryDTO>()
.Name("CompaniesGrid")
.ToolBar(tb => tb.Template(() => { %>
<a href ="#" onclick="createCompany()" >Insert</a>
<% }))
.Columns(col =>
{
col.Bound(c => c.Id).Width(20);
col.Bound(c => c.CompanyName).Width(120);
col.Bound(c => c.ResponsiblePersonFullName).Width(160);
col.Bound(c => c.ResponsiblePersonUserName).Width(160);
col.Bound(c => c.ResponsiblePersonEmail).Width(160);
col.Command(cmd =>
{
cmd.Edit().ButtonType(GridButtonType.Image);
}).Title("Edit");
})
.DataKeys(keys => keys.Add(c => c.Id))
.DataBinding(binding => binding.Ajax()
.Select("_IndexAjax", "Company")
.Insert("_InsertAjax", "Company")
.Update("_UpdateAjax", "Company")
)
.Sortable()
.Render();
%>
<script type="text/javascript">
function createCompany() {
var url = '<%= Url.Action("New", "Company") %>'
$.post(url, function (data) {
var window = $('#CompanyWindow').data('tWindow');
window.content(data);
window.center().open();
});
}
</script>
You will notice in the createCompany function that I call window.center().open(). This explicitly centres the popup.
However, I don't think this is exactly what you want to do, but it may give you some pointers in the right direction. I hope it helps.
Upvotes: 0
Reputation: 2266
Not sure whether this can be done automatically with configuration option - now on the live demos the popup gets centered in the grid. My wild guess is that you can position it in the center of the screen with javascript...
Upvotes: 0