Background color not appearing in free-jqGrid that is present in jqGrid 4.6.0 - jqgrid

I am migrating existing jqGrid (4.6.0) to free-jqGrid (4.13.6 or later). Following two fiddles has same JavaScript and HTML – but one with 4.6.0 jqGrid and the other with free-jqGrid (4.13.6 for now)
jqGrid (4.6.0) Fiddle: https://jsfiddle.net/vth5wn64/2/
free-jqGrid (4.13.6) Fiddle: https://jsfiddle.net/vth5wn64/3/
The free-jqGrid does not have the required background color on the caption area. What is missing here? How to fix this?
JavaScript
function getCurrentPractice ()
{
return "Test";
}
function getGridCaption() {
return "<div style='font-size:15px; font-weight:bold; display:inline; padding-left:10px;'><span class='glyphicon glyphicon-check' style='margin-right:3px;font-size:14px;'></span>" + getCurrentPractice() + " " + "</div>" +
"<div style='float:right; padding-right:20px; padding-bottom:10px; display:inline;>" +
"<div style='float:right;width:550px; padding-bottom:20px;'>" +
"<input type='text' class='form-control' id='filter' placeholder='Search' style='width:250px; height:30px; float:right; ' />" +
" </div>" +
"</div>";
}
$(function () {
////Grid
var myData = [
{ "Practice": "Test1", "ProviderID": 1, "IsPartner": true, "IsActive": true },
{ "Practice": "Test2", "ProviderID": 2, "IsPartner": true, "IsActive": true }
]
var currentPractice = "P";
var grid = $("#list2");
grid.jqGrid({
datatype: 'local',
data: myData,
additionalProperties: ["IsActive", "IsPartner"],
//additionalProperties is needed since the name is different
postData:
{
practiceName: function () { return currentPractice }
},
colNames: [
'Practice',
'ProviderID'
],
colModel: [
{ name: 'Practice', width: 220 },
{ name: 'ProviderID', width: 320 }
],
ignoreCase: true,
loadonce: true,
rowNum: 25,
rowList: [15, 25, 35, 50],
pager: '#pager2',
viewrecords: true,
sortable: true,
caption: getGridCaption(),
beforeSelectRow: function (rowid, e) {
//Avoid selection of row
return false;
},
loadComplete: function () {
}
});
grid.jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
//Filter Toolbar
//grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
$("#advancedSearch").click(function () {
grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
});
//Top Search
$("#filter").on('keyup', function () {
var searchFiler = $("#filter").val(), f;
//alert(searchFiler);
if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData, { filters: "" });
}
f = { groupOp: "OR", rules: [] };
f.rules.push({ field: "Practice", op: "cn", data: searchFiler });
grid[0].p.search = true;
$.extend(grid[0].p.postData, { filters: JSON.stringify(f) });
grid.trigger("reloadGrid", [{ page: 1, current: true }]);
});
});
HTML
<div style="float:left;">
<div id="divGrid" style="width: 680px; min-height: 50px; float: left;">
<table id="list2"></table>
<div id="pager2"></div>
</div>
</div>

First of all, both demos uses classes glyphicon, glyphicon-check and form-control. Thus I suppose that you use Bootstrap CSS additionally to jQuery UI CSS.
I'm not sure, which exact layout you want to have, but one thing is definitively a problem. You use inner divs with float:right inside of the capture (title) div. It's well known that the classic alignment of blocks using float property has the problem. One solves it typically by including some helper element (for example one more div) which has clear: both;. jQuery UI CSS contains ui-helper-clearfix class, which simplifies applying float wrapping properties to parent elements.
In short, you need just add additional
<div class='ui-helper-clearfix'></div>
at the end on the content, which you insert in the caption of jqGrid. See https://jsfiddle.net/vth5wn64/5/

Related

How to implement jqgrid multiselect toolbar

Currently free-jqgrid has feature that supports multiselect toolbar, same feature i want to create in jqgrid also.
http://www.ok-soft-gmbh.com/jqGrid/OK/MultiselectIn.htm
More recent code of usage multiselect with free jqGrid can be seen on the demo https://jsfiddle.net/OlegKi/ty4e68pm/16/. The most important parts of the demo I include below:
var dataInitMultiselect = function (elem, searchOptions) {
var $grid = $(this);
setTimeout(function() {
var $elem = $(elem),
id = elem.id,
inToolbar = searchOptions.mode === "filter",
options = {
selectedList: 2,
height: "auto",
checkAllText: "all",
uncheckAllText: "no",
noneSelectedText: "Any",
open: function() {
var $menu = $(".ui-multiselect-menu:visible");
$menu.width("auto");
$menu.css({
width: "auto",
height: "auto"
});
$menu.children("ul").css({
maxHeight: "300px",
overflow: "auto"
});
}
},
$options = $elem.find("option");
if ($options.length > 0 && $options[0].selected) {
$options[0].selected = false; // unselect the first selected option
}
if (inToolbar) {
options.minWidth = "auto";
}
$grid.triggerHandler("jqGridRefreshFilterValues");
$elem.multiselect(options);
// replace icons ui-icon-check, ui-icon-closethick, ui-icon-circle-close
// and ui-icon-triangle-1-s to font awesome icons
var $header = $elem.data("echMultiselect").header;
$header.find("span.ui-icon.ui-icon-check")
.removeClass("ui-icon ui-icon-check")
.addClass("fa fa-fw fa-check");
$header.find("span.ui-icon.ui-icon-closethick")
.removeClass("ui-icon ui-icon-closethick")
.addClass("fa fa-fw fa-times");
$header.find("span.ui-icon.ui-icon-circle-close")
.removeClass("ui-icon ui-icon-circle-close")
.addClass("fa fa-times-circle");
$elem.data("echMultiselect")
.button
.find("span.ui-icon.ui-icon-triangle-1-s")
.removeClass("ui-icon ui-icon-triangle-1-s")
.addClass("fa fa-caret-down")
.css({
float: "right",
marginRight: "5px"
});
}, 50);
},
multiselectTemplate = {
stype: "select",
searchoptions: {
generateValue: true,
//noFilterText: "Any",
sopt: ["in"],
attr: {
multiple: "multiple",
size: 3
},
dataInit: dataInitMultiselect
}
};
declares multiselectTemplate template. The next code fragment uses the template in colModel
colModel: [
...
{
name: "ship_via", width: 85, align: "center",
template: multiselectTemplate
},
...
],
Finally loadComplete include the code, which create filter toolbar after the data are loaded from the server:
loadComplete: function () {
if (!this.ftoolbar) {
// create filter toolbar if it isn't exist
$(this).jqGrid("filterToolbar", {
defaultSearch: "cn",
beforeClear: function() {
$(this.grid.hDiv)
.find(".ui-search-toolbar button.ui-multiselect")
.each(function() {
$(this).prev("select[multiple]").multiselect("refresh");
});
}
});
$(this).triggerHandler("jqGridRefreshFilterValues");
$(this.grid.hDiv)
.find(".ui-search-toolbar button.ui-multiselect")
.each(function() {
$(this).prev("select[multiple]")
.multiselect("refresh");
});
}
},
If required one can reload the data in filter toolbar by destroying it by destroyFilterToolbar method and executing the same code fragment which create it once more (I mean above code inside of loadComplete).

On subgrid of jqGrid, the right border is not visible

I'm using the free jqGrid version 4.15.0, and I have a subgrid in the main grid and the right border of the subgrid is not visible.
jQuery version: 1.12.4
jQuery UI version: 1.11.4
fontawesome version: 4.7.0
See my fiddle or below code snippet: https://jsfiddle.net/eL7h9e8z/
You'll need to click the + sign to show the subgrid.
var maingriddata = [{
Column1: "Test1",
Column2: "Test1",
ShowSubGrid: true
}, {
Column1: "Test2",
Column2: "Test2",
ShowSubGrid: false
}];
var subgridData = [{
SubCol1: 'SubCol1',
SubCol2: 'SubCol2',
SubCol3: 'SubCol3'
}, {
SubCol1: 'SubCol11',
SubCol2: 'SubCol22',
SubCol3: 'SubCol33'
}];
$(function() {
"use strict";
var $grid = $("#policyGrid");
$grid.jqGrid({
datatype: "local",
data: maingriddata,
colNames: ["Column1", "Column2", "", ""],
colModel: [{
name: "Column1",
width: 50
}, {
name: "Column2"
}, {
name: "viewsubgrid",
align: "center",
width: 21,
formatter: function(cellvalue, options, rowObject) {
if (rowObject.ShowSubGrid) {
return "<span class='fa fa-fw fa-plus subgridIcon'></span>";
} else {
return " ";
}
}
}, {
name: "ShowSubGrid",
hidden: true
}],
cmTemplate: {
sortable: false,
resizable: false
},
iconSet: "fontAwesome",
loadonce: true,
altRows: true,
caption: "",
width: '100%',
height: '100%',
shrinkToFit: true,
autowidth: true,
height: 380,
pgbuttons: false,
pgtext: null,
toppager: false,
pager: true,
rownumbers: false,
threeStateSort: false,
subGrid: true,
subGridOptions: {
hasSubgrid: function(options) {
return options.data.ShowSubGrid;
},
reloadOnExpand: false,
openicon: "ui-helper-hidden"
},
subGridRowExpanded: function(subgridDivId, rowId) {
var subgrid_table_id, pager_id;
subgrid_table_id = subgridDivId + "_t";
pager_id = "p_" + subgrid_table_id;
var $table = $("<table id='" + subgrid_table_id + "' class='scroll'></table>");
$("#" + subgridDivId).append($table);
$("#" + subgrid_table_id).jqGrid({
datatype: "local",
data: subgridData,
colNames: ['Sub Col 1', 'Sub Col 2', 'Sub Col 3'],
colModel: [{
name: "SubCol1",
width: 100,
resizable: false
}, {
name: "SubCol2"
}, {
name: "SubCol3"
}, ],
cmTemplate: {
sortable: false
},
rowNum: 0,
pgbuttons: false,
pgtext: null,
sortable: false,
toppager: false,
viewrecords: true,
pager: true,
rownumbers: false,
height: '80px',
autoresizeOnLoad: true,
idPrefix: subgridDivId + "_" + rowId + "_",
loadComplete: function(data) {
$("#" + subgrid_table_id).jqGrid("setGridHeight", '100%');
},
beforeSelectRow: function(rowid, e) {
return false;
}
}).unbind("contextmenu");
$("#" + subgrid_table_id).jqGrid('navGrid', {
add: false,
edit: false,
del: false,
refresh: false,
search: false
});
},
beforeSelectRow: function(rowid, e) {
var iCol = $.jgrid.getCellIndex(e.target);
if (iCol == $grid.jqGrid("getGridParam", "iColByName")['viewsubgrid']) {
var $btn = $(e.target).closest("td").find('.subgridIcon');
var $tr = $(e.target).closest("tr.jqgrow");
if ($tr.find(">td.sgcollapsed").length > 0) {
$(this).jqGrid("expandSubGridRow", rowid);
$btn.removeClass('fa-plus').addClass('fa-minus');
} else {
$(this).jqGrid("collapseSubGridRow", rowid);
$btn.removeClass('fa-minus').addClass('fa-plus');
}
}
return false;
}
}).jqGrid("navGrid", {
add: false,
edit: false,
del: false,
refresh: false,
search: false
})
.jqGrid("hideCol", "subgrid")
.unbind("contextmenu");
});
.ui-helper-hidden {
display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type='text/javascript'>
$.jgrid = $.jgrid || {};
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.0/jquery.jqgrid.src.js"></script>
<link href="https://code.jquery.com/ui/1.11.4/themes/redmond/jquery-ui.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.0/css/ui.jqgrid.css" rel="stylesheet"/>
<div id="pnlGrid" style="margin-left: 10px; margin-right: 10px;width:700px;">
<table id="policyGrid">
</table>
</div>
Missing border image:
I've noticed that if I reduce (manually) '.ui-jqgrid-hdiv','.ui-jqgrid-bdiv' & '.ui-jqgrid-pager' by 2px, the border is visible.
Anybody has an idea?
Thanks.
Thank you for the bug report and for the demo, which reproduces the problem!
The reason of the problem is the usage of wrong box-sizing on .ui-jqgrid (outer div of the grid) in case of grid as subgrid. The box-sizing of all jqGrid elements should be border-box with the only exception .ui-jqgrid, which should be content-box. One can fix the problem by adding the following additional CSS rules:
.subgrid-data > .tablediv > .ui-jqgrid {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
.subgrid-data > .tablediv > .ui-jqgrid > .ui-jqgrid-view {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
The first rule reset box-sizing of .ui-jqgrid to content-box and the next one changes it back to border-box for children of .ui-jqgrid-view. I updated the main code of ui.jqgrid.css on GitHub too (see the commit).
The demo https://jsfiddle.net/OlegKi/eL7h9e8z/2/ demonstrates working of the changes. I made some other small changes in your code to fix some minor problems.

Kendo grid column lock issue

I have a big problem with a Kendo grid when locking columns. The grid has two static columns and one or more columns created dynamically. Without locking any column, the grid works just fine, when i'm locking the static columns (or just one of them), the grid goes mad.
I know that locking columns will create two different tables (with locked and unlocked columns) but in my case, these tables (with different divs) won't align in my page.
I tried to align them manually using CSS (display:inline-block and/or float: left) but when I resize the window, the grid comes back to the wrong form.
I attached two examples:
In the second example, the rest of the columns are situated somewhere under the page (i need to zoom out to see them).
Inserted simplified code (without locked applied)
Code for columns:
var columns = [
{
field: "Field_Locked1",
title: "F1",
editor: "",
attributes: { style: "text-align: left;" },
sortable: false,
footerTemplate: "T",
width: "30px"
},
{
field: "Field_locked2",
title: "F2",
editable: false,
attributes: { style: "text-align: left;" },
template: "#=test(string)#",
footerTemplate: "<div style='text-align: right;'>1</div><hr/><div style= 'text-align: right;'>2</div>",
width: "370px",
sortable: false
}
];
for (var i = 0; i < customColumns.length; i++) {
var itemTab = customColumns[i];
var dinamicColumn = {
field: itemTab.Name,
title: itemTab.Code,
editable: false,
type: "number",
attributes: { style: "text-align: right;" },
sortable: false,
width: "200px",
template: "#= test(string)#",
footerTemplate: "<div style='text-align: right;'>1</div><hr/><div style= 'text-align: right;'>2</div>"
};
columns.splice(columns.length, 0, dinamicColumn);
}
Code for creating grid:
function createGridGeneric(tabElement,columns) {
var gridModel = tabElement.templateDescription.grid;
var idGrid = gridModel.id;
var gridToolbal = gridModel.toolbar != null ? gridModel.toolbar:null;
var gridFooter = gridModel.footer != null ? gridModel.footer : null;
var hasArea = tabElement.filterArea != null ? tabElement.filterArea.visible : false;
var grid = $("#" + idGrid).data("kendoGrid");
if (grid != null) {
$("#" + idGrid).empty();
}
$("#" + idGrid).kendoGrid({
autoBind: false,
columns: columns,
editable: false,
filterable: false,
groupable: false,
selectable: false,
sortable: false,
scrollable: true,
resizable: true,
save: function(e) {
},
saveChanges: function(e) {
},
columnResize: function(e) {
gridColumnResize(e);
},
databound: function(e) { }
});
return grid;
}

jqGrid add buttons for add/edit/delete in toolbar not working

I have tried to implement the code for adding buttons in jqGrid toolbar from the example site http://www.guriddo.net/demo/bootstrap/ but I'm surprised to find that it isn't working for me. Searched for a couple of hours but I can't figure it out. Here is my code:
<script type="text/javascript">
$(function () {
var gridDataUrl = '#Url.Action("JsonCategories", "AdminNomCategory")'
var grid = $("#reportsGrid").jqGrid({
url: gridDataUrl,
datatype: "json",
mtype: 'POST',
colNames: [
'#Html.DisplayNameFor(model => model.CategoryGuid)',
'#Html.DisplayNameFor(model => model.CategoryName)',
'#Html.DisplayNameFor(model => model.CategoryDescription)'
],
colModel: [
{ name: 'CategoryGuid', index: 'CategoryGuid', width: 10, align: 'left', classes: "nts-grid-cell", hidden: true },
{ name: 'CategoryName', index: 'CategoryName', width: 10, align: 'left', classes: "nts-grid-cell" },
{ name: 'CategoryDescription', index: 'CategoryDescription', width: 10, align: 'left', classes: "nts-grid-cell" }
],
rowNum: 20,
rowList: [10, 20, 30],
height: 450,
width: 1140,
pager: '#pager', /*jQuery('#pager'),*/
sortname: 'CategoryGuid',
toolbarfilter: true,
viewrecords: true,
sortorder: "asc",
caption: "Categories",
ondblClickRow: function (rowid) {
var gsr = jQuery("#reportsGrid").jqGrid('getGridParam', 'selrow');
if (gsr) {
var CategoryGuid = grid.jqGrid('getCell', gsr, 'CategoryGuid');
window.location.href = '#Url.Action("Edit", "AdminNomCategory")/' + CategoryGuid
}
else {
alert("Please select Row");
}
},
#*onSelectRow: function (rowid) {
var gsr = jQuery("#reportsGrid").jqGrid('getGridParam', 'selrow');
if (gsr) {
var CategoryGuid = grid.jqGrid('getCell', gsr, 'CategoryGuid');
window.location.href = '#Url.Action("Edit", "AdminNomCategory")/' + CategoryGuid
}
else {
alert("Please select Row");
}
}*#
});
//jQuery("#reportsGrid").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });
var template = "<div style='margin-left:15px;'><div> Customer ID <sup>*</sup>:</div><div> {CustomerID} </div>";
template += "<div> Company Name: </div><div>{CompanyName} </div>";
template += "<div> Phone: </div><div>{Phone} </div>";
template += "<div> Postal Code: </div><div>{PostalCode} </div>";
template += "<div> City:</div><div> {City} </div>";
template += "<hr style='width:100%;'/>";
template += "<div> {sData} {cData} </div></div>";
$('#reportsGrid').navGrid('#pager',
// the buttons to appear on the toolbar of the grid
{ edit: true, add: true, del: true, search: false, refresh: false, view: false, position: "left", cloneToTop: false },
//// options for the Edit Dialog
{
editCaption: "The Edit Dialog",
template: template,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
// options for the Add Dialog
{
template: template,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
// options for the Delete Dailog
{
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
}
);
grid.jqGrid('filterToolbar', { searchOnEnter: true, enableClear: false });
jQuery("#pager .ui-pg-selbox").closest("td").before("<td dir='ltr'>Rows per page </td>");
grid.jqGrid('setGridHeight', $(window).innerHeight() - 450);
});
$(window).resize(function () {
$('#reportsGrid').jqGrid('setGridHeight', $(window).innerHeight() - 450);
});
</script>
I am using jqGrid 4.4.4 and ASP.NET. The thing I noticed, is that on the example page, the buttons are located inside a div with an id like 'jqGridPagerLeft', but on my page, that div has no id. So I went looking inside the jqGrid source but I'm lost and I can't figure out why it doesn't have an id allocated.
Any clues? I just want to add the buttons to the bottom toolbar. Thx!

Free Jqgrid and custom formatter checkbox

When I click at last column checkbox, nothing happens.
//$.fn.jqm = false;
$.jgrid.jqModal = $.jgrid.jqModal || {};
$.extend(true, $.jgrid.jqModal, {toTop: true});
$("#Ecran").dialog({
//dialogClass: 'Ecran',
autoOpen: false,
width: 560,
height: 370,
modal: true,
open: function (event, ui) {
$("#jqGrid").jqGrid({
url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/getjsonp.php?callback=?&qwery=longorders',
mtype: "GET",
datatype: "jsonp",
colModel: [
{ label: 'OrderID', name: 'OrderID', key: true, width: 75 },
{ label: 'Customer ID', name: 'CustomerID', width: 150 },
{ label: 'Order Date', name: 'OrderDate', width: 150 },
{ label: 'Freight', name: 'Freight', width: 150 },
{ label:'Ship Name', name: 'ShipName', width: 150 },
{name:'ok',index:'ok', width:60,formatter:danu_094,align:'center',search:false}
],
cmTemplate: { width: 80, autoResizable: true },
autoResizing: { compact: true },
autoresizeOnLoad: true,
height: "auto",
viewrecords: true,
rownumbers:true,
//width: 480,
height: "200",
rowNum: 30,
rowList:[5,10,20,30,35],
pager: "#jqGridPager"
}).jqGrid("navGrid", { del: true, add: false, edit: false });
},
close:function () {}
});
$("#Ecran").dialog("open");
function danu_094 (val, options){
idrow=options.rowId;
var checked=(val == 'T') ? "checked='checked'" : "";
return '<input type="checkbox"' + checked + ' value="'+ val+ '" id='+ 'prel_'+idrow+' onchange="senddata_094('+idrow+')" /> ';
}
function senddata_094 (id){ //alert(id);
idelem=$('#prel_'+id);
if ((idelem).is(':checked')) idelem.val('T');
else idelem.val('F');
var sqldate = "&id="+id+"&preluat="+idelem.val();
alert(sqldate);
}
For demo please see http://jsfiddle.net/9ezy09ep/22/
It's unclear what you want to do with the code. In any way it contains many errors. For example you use
function danu_094 (val, options){
idrow=options.rowId;
var checked=(val == 'T') ? "checked='checked'" : "";
return '<input type="checkbox"' + checked + ' value="'+ val+ '" id='+ 'prel_'+
idrow+' onchange="senddata_094('+idrow+')" /> ';
}
where variable idrow is not declared. You should use " checked='checked'" instead of "checked='checked'".
The next problem: senddata_094 which you use needed be defined as global function. So you have to use for example
window.senddata_094 = function (id) {
...
}
or
senddata_094 = function (id){
...
}
where senddata_094 in not defined.
instead of
function senddata_094 (id){
...
}
The next problem: you use idelem variable inside of senddata_094.
By the way you can change ' onchange="senddata_094('+idrow+')" /> ' to ' onchange="senddata_094.call(this,'+idrow+')" /> '. It will initialize this inside of senddata_094 to the checkbox. You can use $(this) instead of $('#prel_'+id) in the senddata_094 function. Thus you will don't need to set any id attribute on the checkbox.
In the same you don't need to set any onchange attribute at all. Instead of that you can define change event on the grid level. The event handler will be called because of event bubbling:
$("#jqGrid").bind("change", function (e) {
var rowid = $(e.target).closest("tr.jqgrow").attr("id");
alert("changed id=" + rowid);
});

Resources