Popup window in Telerik MVC Grid without using Ajax - model-view-controller

In telerik mvc grid i want to display some data in popup window when i click on a link button. But not using Ajax. Below is the code i am using but it is not working. Any help is appreciated
#section JavaScript{
<script type="text/javascript" language="javascript">
$(function () {
$(".lnkShortCodeAndKeyword").click(
function (e) {
e.preventDefault();
var WShortCodeAndKeyword = $.telerik.window.create({
name: "ShortcodesWindow",
title: "Shortcodes",
contentUrl: $(this).attr('href'),
modal: true,
resizable: true,
draggable: true,
scrollable: true,
width: 960,
height: 600,
onClose: function () {
destruir(this);
}
}).data('tWindow').center();
}
}

If you are not using the Window component anywhere on your View (by using Html.Telerik().Window() for example) you will have to manually add the required JavaScript files when you define your ScriptRegistrar. Normally, if you declare the components on the page the ScriptRegistrar takes care of everything for you, but if you just try to create this on the client-side you will have to do something along the following lines:
#(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Add("telerik.common.js").Add("telerik.draganddrop.js").Add("telerik.window.js").Combined(true).Compress(true)))
As you can see I just manually defined the JavaScript files I wanted to load. Keep in mind to not add the "min" suffix as the ScriptRegistrar takes care of this as well (.min.js will only be used in production code and not debug).

Related

Kendo Window not opening again once it is destroyed

I have a situation where I need to destroy kendo window once my job is complete.
Kendo window opens up on a button click and destroys when its job is complete.
But now I have a problem that I cannot open the window again on that button click once it is destroyed.
My Kendo Window code is :
var Snapshotwindow = $('#newWindow');
Snapshotwindow.kendoWindow({
width: "500px",
height: "267px",
resizable: false,
sortable: false,
modal: true,
draggable: false,
title: "New Window",
visible: false,
appendTo: "#AppBody",
});
Snapshotwindow.data("kendoWindow").center().open();
How can I achieve it?
Can I re initialize the window once it is destroyed?
When a kendo Window widget is destroyed, it removes it's HTML elements from the DOM including the root element from which it was created. This is why you are unable to open the window a second time. This leaves you with two basic approaches when using the Window widget:
Create the widget first time around, holding a reference to it. Don't destroy on close, and re-open subsequent times using the reference.
if (Snapshotwindow == null) {
Snapshotwindow = $('#newWindow').kendoWindow({
width: "500px",
height: "267px",
resizable: false,
sortable: false,
modal: true,
draggable: false,
title: "New Window",
visible: false,
appendTo: "#AppBody",
}).data("kendoWindow");
}
Snapshotwindow.center().open();
Append a new element to the DOM, turning that into a window widget before showing it. Can be safely destroyed, and the process subsequently repeated as many times as you like.
<script id="modal-editor-window" type="text/x-kendo-template">
<!-- your window content here -->
</script>
<script type="text/javascript">
var options = {
title: "Edit",
modal: true,
visible: false,
deactivate: function () {
this.destroy();
}
};
var mew = $.parseHTML($("#modal-editor-window").html().trim());
$("body").append(mew);
var mw = $(mew).kendoWindow(options).data("kendoWindow");
mw.center().open();
</script>
Since you say you need to destroy the window, option 2 is the way to go; I would suggest that loading the new DOM element is probably easiest to achieve by using a kendo template (as shown above).

free jqgrid - jqGrid warning dialog

All,
I'm trying to implement custom warning message like 'Please Select row' when toolbar button[top pager] is pressed. I don't want to use alert!!
I followed one of the examples from Oleg(JqGrid guru atleast to me!!)
i.e.Stackoverflow reference - jqGrid warning dialog.
Oleg demo reference - http://www.ok-soft-gmbh.com/jqGrid/Warning.htm
All works well if i use the version same as in Oleg demo. BUT if i change the jqGrid version 4.8.0, the same demo not working :(
I used -
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.8.0/js/jquery.jqgrid.src.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.8.0/css/ui.jqgrid.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.8.0/js/i18n/grid.locale-en.js"></script>
instead of
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.0/js/jquery.jqGrid.src.js"></script>
<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.0/css/ui.jqgrid.css" />
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.0/js/i18n/grid.locale-en.js"></script>
Any idea whether modal usage changed in later version ?
Best Regards,
Sundar
First of all I would recommend you to use the latest version of free jqGrid. It's 4.9.2. You can download it from GitHub or use from CDN directly (see here). The corresponding URLs will be
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/css/ui.jqgrid.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/js/jquery.jqgrid.min.js"></script>
and optionally the language file
<script src="https://cdn.jsdelivr.net/free-jqgrid/4.9.2/js/i18n/grid.locale-de.js"></script>
Including of English locale file grid.locale-en.js is not required, because it's included now in the main code of free jqGrid (jquery.jqgrid.min.js or jquery.jqgrid.src.js).
Before I explain the problems in the old demo I would recommend you to use simplified method $.jgrid.info_dialog to create small dialog. The corresponding code could be
$grid.jqGrid("navButtonAdd", {
caption: "Click me too!",
onClickButton: function () {
$.jgrid.info_dialog.call(this,
"Warning", // dialog title
"Please, select row!", // text inside of dialog
"Close", // text in the button
{ left: 100, top: 100 } // position relative to grid
);
}
});
The displayed dialog will be like below
If you want use text elements from locale file then the code could be modified to the following
$grid.jqGrid("navButtonAdd", {
caption: "Click me too!",
onClickButton: function () {
var $self = $(this),
alertText = $self.jqGrid("getGridRes", "nav.alerttext"),
alertTitle = $self.jqGrid("getGridRes", "nav.alertcap"),
bClose = $self.jqGrid("getGridRes", "edit.bClose");
$.jgrid.info_dialog.call(this,
alertTitle, // dialog title
alertText, // text inside of dialog
bClose, // text in the button
{ left: 100, top: 100 } // position relative to grid
);
}
});
If you want to display exactly the same alert dialog which displays free jqGrid if no row is selected then the code could be especially simple
$grid.jqGrid("navButtonAdd", {
caption: "Click me!",
onClickButton: function () {
this.modalAlert();
}
});
In the case you can't customize the texts, but the usage is really simple.
If you want to use createModal and viewModal like in old demo you should understand the following. There are of cause many changes in free jqGrid. The main compatibility problem in the code: one should call $.jgrid.createModal by setting this to the DOM of the grid. So one have to modify $.jgrid.createModal(...) in the old demo to $.jgrid.createModal.call(this,...). The next problem in the old demo very simple. The condition $("#"+alertIDs.themodal).html() === null is wrong in the current versions of jQuery and one should better use $("#"+alertIDs.themodal).length === 0 instead. It's the next main problem in the old demo. The full code could be for example the following
$grid.jqGrid("navButtonAdd", {
caption: "Click me!",
onClickButton: function () {
var $self = $(this),
p = $self.jqGrid("getGridParam"),
gridId = p.id,
alertIDs = {
themodal: "myalertmod_" + gridId,
modalhead: "myalerthd_" + gridId,
modalcontent: "myalertcnt_" + gridId
},
alertSelector = "#" + $.jgrid.jqID(alertIDs.themodal),
alertText = $self.jqGrid("getGridRes", "nav.alerttext"),
alertTitle = $self.jqGrid("getGridRes", "nav.alertcap");
if ($(alertSelector).length === 0) {
$.jgrid.createModal.call(this,
alertIDs,
"<div>" + alertText + "</div>",
{
gbox: p.gBox,
jqModal: true,
drag: true,
resize: true,
caption: alertTitle,
top: 100,
left: 100,
width: 200,
height: "auto",
closeOnEscape: true,
zIndex: null
},
"", "", true);
}
$.jgrid.viewModal(
alertSelector,
{
gbox: p.gBox,
toTop: true
});
}
});

KendoUI Window size too large when iframe used

I am trying to load different static html files into a KendoWindow based on a link the user clicks. I am using the following to load the content.
$(document.body).append('<div id="formWindow"></div>');
$('#formWindow').kendoWindow({
visible: false,
iframe: true,
height: "auto",
maxWidth: 700,
title: noticeTitle,
modal: true,
resizable: true,
width: 700,
refresh: function() {
this.center();
},
close: function(e) {
var dialog = $("#formWindow").data("kendoWindow");
dialog.destroy();
},
content: formContent
});
When I use "iframe: false", the window size (height) is the correct size. However I need an iframe because sometimes the loaded page is a form for submitting data and I don't want the whole browser page to change, just the contents of the KendoWindow. When "iframe: true" is used, the KendoWindow size is almost the height of the browser screen (i.e. way too tall).
I would like to be able to adjust the window to fit the dynamically loaded contents, but I cannot figure out how to use JavaScript or JQuery to get the height of the window contents.
My content is always balanced tags and a page fragment (i.e. no tags).
Thanks!
I don't think you can. However, I found this: http://www.telerik.com/forums/automatic-width-and-height-on-window#Gx4FWdFC8EG4JXoxoq2PLw

JQgrid on refresh button click

I want to write code on Refresh button click of JQGrid. Is there any event for that?
If you need to do some actions before refresh will be started you should use beforeRefresh callback:
$("#grid_id").jqGrid('navGrid', '#gridpager', {
beforeRefresh: function () {
// some code here
}
});
If you need absolute another implementation of grid Refreshing where you will not call $("#grid_id").trigger("reloadGrid"); (which sound strange) you can do this by the usage of refresh: false option to remove the standard Refresh button and using navButtonAdd to add your custom button which looks exactly like the original one:
$("#grid_id").jqGrid('navGrid', '#gridpager', {refresh: false});
$("#grid_id").jqGrid('navButtonAdd', "#gridpager", {
caption: "", title: "Reload Grid", buttonicon: "ui-icon-refresh",
onClickButton: function () {
alert('"Refresh" button is clicked!');
}
});
The css for refresh button is ui-icon-refresh
so you can write your custom code on this css like
jQuery('.ui-icon-refresh').click(function(){
// do your work
});

Issue when using Galleria theme with ASP.NET MVC3

I am trying to use the galleria photo gallery.
Issue: The theme loading code
Galleria.loadTheme('/galleria/themes/classic/galleria.classic.min.js'); works fine only when we are using it in the default action of home controller i.e. Home/Index
I was using the theme on a View called Display. so i wrote an action in Home to return Display view.
The images must be showing in the Galleria theme photo viewer, but they show up as images one after other instead.
If i try and call the display view from Index action, it works fine. but i want to do something else in the Index view.
any help will be greatly appreciated.
The theme script does not seem to be loading. The cause can be a virtual path issue.
I´m used to use the Galleria plugin in this way:
<script src="#Url.Content("~/Scripts/JQuery.Galleria/1.2.5/galleria-1.2.5.min.js")" type="text/javascript"></script>
<script type="text/javascript">
var virtualPath = '#Url.Content("~/")';
$(document).ready(function () {
Galleria.loadTheme(virtualPath + '/Scripts/jQuery.Galleria/1.2.5/themes/twelve/galleria.twelve.min.js');
// Initialize Galleria
$('#galleria').galleria({ autoplay: false, /* true, miliseconds */
thumbnails: true, /*true, false, numbers, empty */
imageCrop: true, /*true, false, height, width */
transition: "pulse", /*fade, fadeslide, slide, flash, pulse */
trasitionSpeed: 500,
thumbFit: true
});
});
</script>
Hope this helps.

Resources