JqGrid reposition the of Add button - jquery-ui

Am a beginner in jqGrid ,where am using navGrid, for Add(Which is used for File Upload), when i click on add button, it pops up a Modal dialog in top, leftside of the page.its very uneasy to go the top and come again is there any way to position the Add dialog and it should show up next to the + button ?
jQuery(table).jqGrid('navGrid',pager,{edit:false,add:true,del:false,search:false,refresh:true,cloneToTop:true},{},{addCaption:'Add',width:500,recreateForm: true,reloadAfterSubmit:false,closeAfterAdd:true,closeAfterEdit: true, closeOnEscape:true, afterSubmit : UploadAttachedFile });

You can change position of Add dialog inside of afterShowForm callback. For example you can use jQuery UI Position to do this.
The demo use the following code
var $grid = $("#list");
...
$grid.jqGrid('navGrid', '#pager', {del:false}, {}, {
afterShowForm: function ($form) {
$form.closest(".ui-jqdialog").position({
of: "#add_" + $.jgrid.jqID($grid[0].id),
at: "left bottom",
my: "right top"
});
}
});
and the results looks like on the picture below
You can change the values of at and my properties of position to have exact results which you need.

Try this:
Add this to your code of Add button
top:400,left:20
your code should look like:
jQuery(table).jqGrid('navGrid',pager,{edit:false,add:true,del:false,search:false,refresh:true,cloneToTop:true},
{},
{
addCaption:'Add',
width:500,
recreateForm: true,
reloadAfterSubmit:false,
closeAfterAdd:true,
closeAfterEdit: true,
closeOnEscape:true,
afterSubmit : UploadAttachedFile,
top:400, //position from top
left:20 //position from left
});

Related

How to change class on underlying element for the duration of the jQuery UI tooltip display

I want to implement a feature somewhat like (but not exactly like) the hint mode of the Mahjong Titans game in Windows. In that game, you can ask the game to show you a tile that matches the tile you're on.
In my app, when the user hovers the pointer over a cell of my table, I want to display a tooltip but also add a class to the underlying cell, as well as to some other related cells, in order to highlight these cells for the duration of the tooltip display; the highlight would disappear when the tooltip closes.
The cell click event is already dedicated to some other behavior. This related-cells-highlighting behavior must be an ancillary behavior of the tooltip.
I am creating the tooltip like this now:
$("#my-table tbody td.foo").tooltip({
content: function () {
// figure out the custom message to be displayed
}
},
items: "td.foo",
position: { my: "left+15 center", at: "left top" },
show: {
delay: 666
}
})
Can this instantiation approach be extended with functions that are invoked when the tooltip is displayed and when the tooltip is taken down?
In the function tied to the tooltip's opening, I would figure out which cells are involved and add the correct class to them; in the function related to the tooltip's closing, I would remove that class from those cells.
I think you're looking for the open and close events.
$("#my-table tbody td.foo").tooltip({
content: function () {
// figure out the custom message to be displayed
},
items: "td.foo",
position: {
my: "left+15 center",
at: "left top"
},
show: {
delay: 666
},
open: function (event, ui) {// do stuff when tooltip opens...
},
close: function (event, ui) {// do other stuff when tooltip closes...
}
});

jquery dialog - push the background content down

I'm having a strange problem with the jquery dialog popup that I'm hoping someone here can help. The pop up codes looks like below. It works fine except for one thing. When the pop-up is displayed, it will sometimes push the background content down by about the height of the the dialog window. Is there a way to prevent this from happenning?
$("#searchPopUp").dialog({
modal: true,
bgiframe: false,
autoOpen: false,
resizable: true,
position:{ my: "center", at: "center", of: window },
title: 'Choose one search criteria and<br/>populate the corresponding field below:',
width: 400,
close: function( event, ui ) {},
buttons: {
"Search": function() {
$("#viewDevicesSearchForm\\:searchCommandLink").click();
},
"Close": function() {
$( this ).dialog( "close" );
}
}
});
This is because jquery sets position to relative, and then moves the popup to the right place using top and left. I found two ways to fix the problem:
1) The easier of the two: set margin-bottom of the dialog container to negative its height.
popup.dialog({
...other options...,
open : function() {
popup.css('margin-bottom', 0 - popup.height());
},
});
2) For the dialog container, set the position to absolute and adjust the top and left. To put it in the right place, add the offset position of where it is getting placed to the top value that jquery set. The calculation is similar for left.This should do it, but different parameters to the dialog may require different calculations.

jQuery UI dialog: clicking on the title bar (including close button) makes the whole dialog scroll up

Everytime I click on the jQuery UI dialog title bar, or the close button, the whole dialog first scrolls up to the top of the screen without triggering any ui events. Then I have to click a second time in order for the close event to be triggered.
Here is my code:
var dialog = $(selector).dialog(
{
autoOpen : true,
modal : true,
title : title,
overlay : {
opacity : "0.1",
background : "black"
},
width : dWidth,
height : dHeight,
autoResize: false,
resizable : true,
effect: 'fade',
zIndex: 100,
close: function(ev, ui) {
if(callback){
callback();
}
}
I have tried to remove all the properties but I still get the bug. I am on jQuery UI 1.8.23, but the same bug appears on 1.9.1.
Any help would be appreciated.
I thing that you have some problems in close: option. Try to remove it or edit it and see what's going on.
Try to put width : dWidth + 'px',
Also try to remove semi colon on callback.
close: function(ev, ui) {
if(callback){
callback()
}
}
It's a bug: http://bugs.jqueryui.com/ticket/3623
Upgrade your jqueryui
This was happening to me in IE, it was not just when clicking buttons but any click after scroll down. Solution was updating jQuery UI http://code.jquery.com/ui/1.11.4/jquery-ui.js

Need help in Kendo Window UI control

I am working on a councelor portal which is a part of our project in company and my boss advised me to use kendow windo pop control for popups on certain links.
I have done it by using the kendo application control but a little problem arouse which makes my look and feel bad a little.
we got links on one page and our application is supposed to show use popup window when any of the link will be clicked but when I actually runs the page then a popup kendo window comes first and when I minimize it or close it then link starts working according to our desire.
I am sure there is some problem with jquery code which shows the popup window on document.ready(function(){}); but it should work when a link is clicked.
I am posting my code here please help me out to make it more refined and good looking
var window = $("#window"),
undo = $("#undo")
.bind("click", function () {
window.data("kendoWindow").open();
window.data("kendoWindow").center();
undo.hide();
});
var onClose = function () {
undo.show();
}
if (!window.data("kendoWindow")) {
window.kendoWindow({
width: "600px",
height: "500px",
draggable: false,
actions: ["Minimize", "Maximize", "Close"],
resizable: false,
title: "Report Activity",
content: "../../AlertCounselor.htm",
close: onClose
});
}
HTML:
<div id="window"></div>
<label id="undo" style="display:none; width:200px;" class="k-group" >Alert Counselor</label>
If you don't want the window to be displayed when the document is loaded, you should specify visible: false in the initialization (check documentation here ).
Lets assume that you have the following link:
Click here for opening the window and not before
Then define the window as:
var myWindow = window.kendoWindow({
visible : false,
width : "600px",
height : "500px",
draggable: false,
actions : ["Minimize", "Maximize", "Close"],
resizable: false,
title : "Report Activity",
content : "../../AlertCounselor.htm",
close : onClose
}).data("kendoWindow");
This should leave the window closed waiting for something else that open it.
Finally define a click event handler for the link:
$("#open").on("click", function() {
myWindow.open();
});

jquery ui tooltip manual open /close

is there a way to manually open close the jquery ui tooltip? I just want it to react to a click event toggling on/off. You can unbind all mouse events and it will rebind them when calling .tooltip('open'), even though that should not initialize or set events imo, since if you try to run .tooltip('open') without initializing, it complains loudly about not being initialized.
jltwoo, can I suggest to use two different boolean switches to enable auto-open and auto-close? With this change your code will look like this:
(function( $ ) {
$.widget( "custom.tooltipX", $.ui.tooltip, {
options: {
autoShow: true,
autoHide: true
},
_create: function() {
this._super();
if(!this.options.autoShow){
this._off(this.element, "mouseover focusin");
}
},
_open: function( event, target, content ) {
this._superApply(arguments);
if(!this.options.autoHide){
this._off(target, "mouseleave focusout");
}
}
});
}( jQuery ) );
In this way, initializing the tooltip as:
$(someDOM).tooltipX({ autoHide:false });
it shows by itself when the mouse is over the element but you have to manually close it.
If you want to manually control both open and close actions, you can simply use:
$(someDOM).tooltipX({ autoShow:false, autoHide:false });
If you want to just unbind the events and woudn't like to make your own custom tooltip.
$("#some-id").tooltip(tooltip_settings)
.on('mouseout focusout', function(event) {
event.stopImmediatePropagation();
});
$("#some-id").attr("title", "Message");
$("#some-id").tooltip("open");
mouseout blocks the tooltop disappearing by moving the mouse cursor
focusout blocks the tooltop disappearing by keyboard navigation
The tooltip have a disable option. Well i used it and here is the code:
$('a').tooltip({
disabled: true
}).click(function(){
if($(this).tooltip('option', 'disabled'))
$(this).tooltip('option', {disabled: false}).tooltip('open');
else
$(this).tooltip('option', {disabled: true}).tooltip('close');
}).hover(function(){
$(this).tooltip('option', {disabled: true}).tooltip('close');
}, function(){
$(this).tooltip('option', {disabled: true}).tooltip('close');
});
Related to my other comment, I looked into the original code and achieved manual open/close by extending the widget and adding a autoHide option with version JQuery-UI v1.10.3. Basically I just remove the mouse listeners that were added in _create and the internal _open call.
Edit: Separated autoHide and autoShow as two separate flags as suggested by #MscG
Demo Here:
http://jsfiddle.net/BfSz3/
(function( $ ) {
$.widget( "custom.tooltipX", $.ui.tooltip, {
options: {
autoHide:true,
autoShow: true
},
_create: function() {
this._super();
if(!this.options.autoShow){
this._off(this.element, "mouseover focusin");
}
},
_open: function( event, target, content ) {
this._superApply(arguments);
if(!this.options.autoHide){
this._off(target, "mouseleave focusout");
}
}
});
}( jQuery ) );
Now when you initialize you can set the tooltip to manually show or hide by setting autoHide : false:
$(someDOM).tooltipX({ autoHide:false });
And just directly perform standard open/close calls in your code as needed elsewhere
$(someDOM).tooltipX("open"); // displays tooltip
$(someDOM).tooltipX("close"); // closes tooltip
A simple hotfix, until I have the time to do official pull request, this will have to do.
Some compilation from other SO questions.
Example
Show tooltip on hint click, and hide tooltip on elsevere click
$(document).on('click', '.hint', function(){ //init new tooltip on click
$(this).tooltip({
position: { my: 'left+15 center', at: 'center right' },
show: false,
hide: false
}).tooltip('open'); // show new tooltip
}).on('click', function(event){ // click everywhere
if(!$(event.target).hasClass('hint'))
$(".hint").each(function(){
var $element = $(this);
if($element.data('ui-tooltip')) { // remove tooltip only from initialized elements
$element.tooltip('destroy');
}
})
});
$('.hint').on('mouseout focusout', function(event) { // prevent auto hide tooltip
event.stopImmediatePropagation();
});

Resources