how show info_dialog set postion center in jqgrid - javascript

iam jqgrid ver 4.15 iam have a problem ..i want add inline record .
filed name is required
{ name: "Name", width: 200, editable: true ,
editrules: {required: true}
}
I want when show position center info_dialog jqGrid popup modal .
iam use help this links and other links but don't work
how to center jqGrid popup modal window?
plase see this demo https://jsfiddle.net/dnfk8hmr/178/
iam want error modal in aling center
enter image description here

You write about adding inline record. Inline editing means editing fields inside of jqGrid. Modal windows will be used in case of form editing. What editing mode you really need to use?
As a workaround I can suggest you to combine form editing with inline editing. You can use form editing for Add operation and inline editing for editing existing lines. The corresponding code could looks like
$("#grid").jqGrid({
...
navOptions: {
edit: false,
del: false,
search: false,
refresh: false
},
inlineNavOptions: {
add: false,
edit: true
},
formEditing: {
beforeShowForm: function ($form) {
var $dlgDiv = $form.closest(".ui-jqdialog"),
dlgWidth = $dlgDiv.width(),
dlgHeight = $dlgDiv.height(),
dlgStyle = $dlgDiv[0].style,
$gridDiv = $(this).closest(".ui-jqgrid"),
gridWidth = $gridDiv.width(),
gridHeight = $gridDiv.height();
// TODO: change parentWidth and parentHeight in case of the grid
// is larger as the browser window
dlgStyle.top = Math.round((gridHeight - dlgHeight) / 2) + "px";
dlgStyle.left = Math.round((gridWidth - dlgWidth) / 2) + "px";
}
}
}).jqGrid("filterToolbar")
.jqGrid("navGrid")
.jqGrid("inlineNav");
see https://jsfiddle.net/dnfk8hmr/196/
UPDATED: If you want to position the dialog in the middle of window instead of the middle of grid and if you include jQuery UI JS file additionally to CSS then the code could be the following
formEditing: {
afterShowForm: function ($form) {
$form.closest(".ui-jqdialog").position({
my: "center",
at: "center",
of: window
});
}
}
see https://jsfiddle.net/dnfk8hmr/202/

Related

ExtJS 5.0 - adding button as overlay to component

We are working with software supplied by a third party, and we are not allowed to modify it, can use only overrides.
I would like to create a new button and overlay it on top of a text input so that they are close together.
I'm having trouble getting the overlay to align, instead it appears top left on the screen. So of course it doesn't align to the text input. Sample code is below, in this case implemented in the view initComponent override after this.callParent([]); is called.
var viewport = Ext.ComponentQuery.query('viewport')[0];
var overlay = viewport.add({
xtype: 'panel',
fullscreen: true,
left: 0,
top: 0,
width: 120,
height: 40,
items:[{
xtype: 'button',
text: 'Find Address',
handler: function() {
alert('Got it!');
}
}],
styleHtmlContent: true
});
var textField = this.query('*[itemId=textField]')[0];
overlay.showBy(textField, 'c-c?');
I've tried using floating: true and lots of other approaches.
Once I get it to position properly, is there a way to have the button respond to tab order correctly? That is, tab out of the text field, then have the button get focus?
As I understand from your question, you have trouble with setting position to a component. If it is the problem, you can set xy coordinate. Look at this fiddle:
https://fiddle.sencha.com/#fiddle/tpl
viewport.down('#idOverlay').setXY([150, 140]);
Edit:
Ext.define('OverriddenViewport', {
override: 'ExampleViewPort',
initComponent: function() {
// Set up first
this.callParent([]);
this.add(overlay);
this.addListener('afterrender', function(viewport) {
viewport.down('#idOverlay').setXY([220,50]);
viewport.down('#idButton').addListener('blur', function(button) {
viewport.down('#idTextfield').focus();
console.log('textfield is focussed');
});
viewport.down('#idTextfield').addListener('blur', function(button) {
viewport.down('#idButton').focus();
console.log('button is focussed');
});
});
}
});
If you can access the source (just to look around) you maybe can create an override of the corresponding class. Create a override, and copy all of the code of the class (form?) into your override.
Here some additional info about creating overrides in ExtJs:
http://moduscreate.com/writing-ext-js-overrides/
https://sencha.guru/2014/12/04/abstract-vs-override/
In your override create a trigger (on the field you want to expand) with your functionality:
{
fieldLabel: 'My Custom Field',
triggers: {
foo: {
cls: 'my-foo-trigger',
handler: function() {
console.log('foo trigger clicked');
}
}
}
}

vBulletin / CKEditor Plugin Disabled in Source Mode

I have this plugin that I want to be enabled in WYSIWYG and Source modes. Here is the simple code:
(function()
{
CKEDITOR.plugins.add('oovideo',
{
init : function(editor)
{
editor.addCommand('oovideo', new CKEDITOR.dialogCommand('oovideo'));
editor.ui.addButton('OOVideo',
{
label: 'OOVideo',
command: 'oovideo',
icon: 'http://www.google.com/favicon.ico',
modes : { source : 1, wysiwyg : 1, enhancedsource : 1 }
});
CKEDITOR.dialog.addIframe(
'oovideo',
'OOVideo',
'http://www.example.com/', 450, 500,
null, null
);
}
});
})();
Currently the button will only pull up the iFrame dialog when in WYSIWYG mode.
Because I added modes : { source : 1, wysiwyg : 1, enhancedsource : 1 } in the button control, the button is not grayed out in all modes, but the button will only function in WYSIWYG mode.
I found some hints in this post:
CKEditor plugin button disabled in source mode
It seems that I have to include the modes variable in the editor.addCommand() call, but I am passing a CKEDITOR.dialogCommand object in that parameter space and not JS code.
What is the best way to pass the dialog object and the mode parameter? Thanks for any assistance!
I found the solution - the editor.addCommmand can be assigned to a variable, and then have the modes property added on a new line.
var command = editor.addCommand('tgroovideo', new CKEDITOR.dialogCommand('tgroovideo'));
command.modes = { wysiwyg:1, enhancedsource:1 };

How to add a jquery ui slider to each cell of slickgrid?

I need to add a jquery ui slider to each cell of slickgrid. Number of records is over 10,000 with over 150 columns. The problem is that the initial set of sliders are rendered fine but as I scroll (left or right), they disappear. Somehow, the grid is not getting invalidated for those cells. I am using the following formatter on the column:
SliderFormatter = function (row, cell, value, colDef, dataContext) {
var html = "<div class='mySlider' id='slider_" + dataContext['id'] + "'></div>" + value;
return html;
}
and invoking the slider from my document.ready callback.
Any help will be appreciated. Thanks in advance !
SlickGrid renders only what's visible in the viewport, plus a small buffer. As you scroll, rows/cells are dynamically added and removed.
What this means for your case, is that when you initialize the slider widget in your document.ready callback, you're only initializing a tiny portion of them, and the ones that did get initialized, don't get re-initialized when the cells they are in are removed and recreated by SlickGrid.
SlickGrid doesn't allow you to use jQuery widgets like the slider in cells and requires that formatters output pure HTML in order to make it hard to implement the grid in a way that will slow it down. (I won't get into my reasoning behind that admittedly controversial decision.)
My advice here is to avoid using the jQuery UI slider here. It is simply not scalable or performant enough. Without virtualization, what you're trying to do is impossible - initializing 100 sliders is going to be really slow; initializing 10'000 x 150 of them is out of the question. With virtualization, you'll need to initialize and destroy them on the fly as you're scrolling around, and that's just too slow to scroll smoothly.
Consider using an HTML5 range input - <INPUT type="range">. It's supported by all major browsers with the exception of IE <10. See http://caniuse.com/#feat=input-range.
I've created an example using SlickGrid's async post-render option. #Tin is probably right that it would be better to use the native <input type="range"> but just in case you need to support older browsers here's how you can do it.
function waitingFormatter(value) {
return '<div class="slider"></div>';
}
function renderSlider(cellNode, row, dataContext, colDef) {
var cell = $(cellNode);
cell.find('.slider').slider({
value: dataContext.value,
slide: function(e, ui) {
data[row].value = ui.value;
cell.prev().html(ui.value);
}
});
}
var grid;
var data = [];
var columns = [
{ id: "title", name: "Title", field: "title", sortable: false, width: 120, cssClass: "cell-title" },
{ id: "value", name: "Value", field: "value", sortable: false, editor: Slick.Editors.Integer, width: 40, validator: requiredFieldValidator },
{ id: "chart", name: "Slider", sortable: false, width: 425, formatter: waitingFormatter, rerenderOnResize: true, asyncPostRender: renderSlider }
];
var options = {
editable: true,
enableAddRow: false,
enableCellNavigation: true,
asyncEditorLoading: false,
enableAsyncPostRender: true
};
$(function () {
for (var i = 0; i < 500; i++) {
var d = (data[i] = {});
d["title"] = "Record " + i;
d["value"] = Math.round(Math.random() * 100);
}
grid = new Slick.Grid("#myGrid", data, columns, options);
})

How to dynamically toggle the `resizable` boolean in the jQuery UI Layout plugin?

Problem
I am using the jQuery UI Layout plugin (layout.jquery-dev.net/index.cfm) in my web application.
Using 2 panels only (center and east), I need to dynamically disable the resizable option of the layout.
function InitializeLayout(sElement) {
var oOptions = {
closable: false,
resizable: true,
slidable: false,
east__livePaneResizing: true,
east__maxSize: 672,
east__minSize: 250,
east__onresize_end: function() {
// GetOverlaySizes();
// SetOverlaySizes();
// SetPaperSizes();
},
east__size: 250
};
oLayout = $(sElement).layout(oOptions);
oLayout.options.east.resizable = false;
console.log(oLayout.options);
}
This doesn't work, even though the resizable option is set to false on the console.
Questions
How do I dynamically disable/enable the resizable option ?
This has nothing to do with my problem, but why does enabling the live pane resizing make Mozilla Firefox (20.0) so slow ?
Thanks,
Solution
oLayout.disableResizable("east");
oLayout.enableResizable("east");
Thanks to #dwaddell.
Here is what you need to do, after the init:
oLayout.disableResizable('east');
Hope that helps.
Here is an updated jsFiddle: http://jsfiddle.net/dwaddell/YE2CQ/

jqGrid - Dragging a row to sort it screws up cell widths

My problem: When I drag a row in jqGrid, and it completes a custom reload function, the cells of the grid, previously all of varying widths set when the grid is defined, are resized to all be the same width. This happens in Webkit browsers but not in Firefox.
Code:
I have dragging to sort enabled on a grid:
$mygrid.jqGrid(
'sortableRows', {
update: function(e, ui) {
sort_grid(e, ui);
}
}
);
As you can see I have a sorting function called on drag complete, sort_grid. Here it is:
function sort_grid(e, ui) {
var current_grid = $(ui.item[0]).closest('table').attr('id');
var $current_row, moved_id, next_id, next_priority;
var $moved_row = $('#' + current_grid + ' tr');
var cnt = 0;
this_id = ui.item[0].id;
$moved_row.each(function () {
if ($(this).attr('id') == this_id) {
$current_row = $moved_row.eq(cnt);
moved_id = $current_row.attr("id");
next_id = $current_row.next().attr("id");
next_priority = $current_row.next().children("td:first").attr("title");
}
cnt++;
});
if ( typeof moved_id !== 'undefined' ) {
if ( next_priority == 'undefined' ) {
next_priority = '999';
}
$.ajax({
url:my_url,
type:"POST",
data:"moved_id=" + moved_id + "&next_id=" + next_id + "&next_priority=" + next_priority,
success: function(data) {
$('.grid').setGridParam({loadonce:false, datatype:'json'}); // force grid refresh from server
$('#' + current_grid).trigger("reloadGrid");
$('.grid').setGridParam({loadonce:true}); // reset to use local values
}
})
}
}
Once I hit that reload trigger $('#' + current_grid).trigger("reloadGrid"); and reload finishes the grid now has incorrect widths on the cells in the grid (they go from being of various widths to all being the same width).
When the grid was originally created it had widths defined in the normal jqGrid fashion:
colModel:[
{name:'one', index:'one', sortable:true, width:45},
{name:'two', index:'two', sortable:true, width:180},
]
but after the grid reload the widths are reset all be the same width (I assume this is the total width of the grid being evenly divided over the total number of cells in the row). So, do I need to explicitly set these widths again, perhaps with something like the following called after the grid reloads?
$('.grid').setGridParam({
colModel:[
{name:'one', index:'one', sortable:true, width:45},
{name:'two', index:'two', sortable:true, width:180},
]
});
I tried the above fix, redefining the colModels after reload and explicitly setting the widths, but it had no effect. Weirder, if I go into the browser console and set the widths with javascript it also has no effect. That's got me stumped.
Unfortunately for me it looks like the jqGrid "Answer Man" (Oleg) is not around... lol.
I faced the same problem for Chrome. I recreated it here http://jsfiddle.net/gZSra/. Just drag the row and then sort any column.
But after few hard hours of debugging jqGrid sources I finally fixed this bug. The problem appears in emptyRows method of jqGrid.
emptyRows = function (scroll, locdata) {
var firstrow;
if (this.p.deepempty) {
$(this.rows).slice(1).remove();
} else {
firstrow = this.rows.length > 0 ? this.rows[0] : null;
$(this.firstChild).empty().append(firstrow); // bug "activation" line
}
if (scroll && this.p.scroll) {
$(this.grid.bDiv.firstChild).css({height: "auto"});
$(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
if (this.grid.bDiv.scrollTop !== 0) {
this.grid.bDiv.scrollTop = 0;
}
}
if(locdata === true && this.p.treeGrid) {
this.p.data = []; this.p._index = {};
}
},
*In recent jqGrid-4.4.4 this code begins from 1070 line of jqGrid.src.js
The problem connected removing and then appending firstrow. This row defines width of columns - one of it's cells in my jsFiddle example is
<td role="gridcell" style="height:0px;width:60px;"></td>
That is why problem seems to be connected with some Chrome's or Webkit's dynamic table behaviour.
FIX
Replace infected else scope with next line
$(this.firstChild).find('tr:not(:first)').remove();
It's not hard to see that instead of removing all lines and then appending first back, I just selecting and removing all except first row.
Result jsFiddle: http://jsfiddle.net/HJ3Q3/
Tested in Chrome, FF, IE 8 & 9.
Hope this fix will soon become part of jqGrid sources.
.trigger('reloadGrid');
is causing issues with sortablerows.
Below work around might help you (Unload & reload grid)
Create a function to configure grid, like below
jQuery().ready(ConfigureGrid);
function ConfigureGrid(){
jQuery("#grdCategory").jqGrid({
url: '/controller/action',
datatype: "xml",
colNames: ['Order', 'Name', 'Page Title', 'Is Active', 'Action'
],
colModel: [
{ name: 'col1', index: 'col1', width: 50, sortable: true, sorttype: 'int' }
, { name: 'col2', index: 'col2', width: 150, sortable: true }
],
rowNum: 10,
rowList: [10, 20, 30],
});
$("#list1").jqGrid('navGrid', '#pager1', { edit: false, add: false, del: false, search: true });
$("#list1").jqGrid('sortableRows', { update: function (event, ui) { updateOrder() } });
}
Create function to reload grid
function loadGrid() {
$('#grdCategory').jqGrid('GridUnload');
ConfigureGrid();
}
use loadGrid() function in ajax call back or to refresh grid
Have you tried to setup this property in your jQgrid options
width: 'auto',
If this doesnt work try reloading your grid after the update of the row
jQuery('.grid').trigger('reloadGrid');
The comment of PokatilovArt needs more attention : jqGrid - Dragging a row to sort it screws up cell widths .
It solves the problem in Chrome.
Here is the parameter to change in jqGrid :
deepempty : true
In jqGrid wiki, here is the definition of this option.
This option should be set to true if an event or a plugin is attached to the table cell. The option uses jQuery empty for the the row and all its children elements. This of course has speed overhead, but prevents memory leaks. This option should be set to true if a sortable rows and/or columns are activated.

Categories