Kendo grid column lock issue - kendo-ui

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;
}

Related

Kendo Grid : Blank space in the end when you resize(reduce) any column

I have a grid and when i resize (reduce) any column, there is a white space shows up in the end of the grid. I have checked with the Kendo official samples and it seems like in some samples the shown behavior is in their samples.
I tried setting up width for header, cell content etc.. but its still shows some UI issues and i have multiple grids and i need a generic fix.
If its not an issue and a behavior then somebody please have a look at this and explain how to fix it.
I have added a normal screen shot and resized screenshot.
normal
after resize
For testing it out, i have added a jsfiddle.,
http://jsfiddle.net/49bhz2sk/
html
<div class="panel panel-body">
<div id="fleetInfoGridDisplayDummy" class="" data-bind="autoHeightContainer:true"></div>
</div>
script
$("#fleetInfoGridDisplayDummy").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
},
pageSize: 20
},
navigatable: true,
selectable: true,
sortable: true,
reorderable: true,
resizable: true,
scrollable: { virtual: true },
columnMenu: true, // Needed to hide and show columns.
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
template: "<div class='customer-photo'" +
"style='background-image: url(../content/web/Customers/#:data.CustomerID#.jpg);'></div>" +
"<div class='customer-name'>#: ContactName #</div>",
field: "ContactName",
title: "Contact Name",
width: 240
}, {
field: "ContactTitle",
title: "Contact Title"
}, {
field: "CompanyName",
title: "Company Name"
}, {
field: "Country",
width: 150
}]
});
I have posted this in telerik forum and got a reply from the admin, here is how they suggested to resolve the issue. Posted here so that someone else can benefit from this.
Answer proposed by 'Drew B.' also works, i have seen that too in another post. The the code i posted is less cumbersome with minimal coding.
columnResize: function (e) {
// what is thead and tbody: https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#fields
var grid = e.sender,
gridHeaderTable = grid.thead.parent(),
gridBodyTable = grid.tbody.parent();
// what is wrapper: https://docs.telerik.com/kendo-ui/api/javascript/ui/widget/fields/wrapper
// what is scrollbar(): https://docs.telerik.com/kendo-ui/api/javascript/kendo/fields/support
if (gridBodyTable.width() < grid.wrapper.width() - kendo.support.scrollbar()) {
// remove the width style from the last VISIBLE column's col element
gridHeaderTable.find("> colgroup > col").last().width("");
gridBodyTable.find("> colgroup > col").last().width("");
// remove the width property from the last VISIBLE column's object
// https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/fields/columns
grid.columns[grid.columns.length - 1].width = "";
// remove the Grid tables' pixel width
gridHeaderTable.width("");
gridBodyTable.width("");
}
},
According to various kendo sources, this is a mixture of observed normal behavior (2013), and unexpected behavior (2017). Kendo does provide a workaround for this issue, as I suspect it isn't necessarily kendo related but more an HTML/Table feature.
<style>
.k-grid {
width: 700px;
}
</style>
<div id="grid1"></div>
<script>
function getMasterColumnsWidth(tbl) {
var result = 0;
tbl.children("colgroup").find("col").not(":last").each(function (idx, element) {
result += parseInt($(element).outerWidth() || 0, 10);
});
return result;
}
function adjustLastColumn() {
var grid = $("#grid1").data("kendoGrid");
var contentDiv = grid.wrapper.children(".k-grid-content");
var masterHeaderTable = grid.thead.parent();
var masterBodyTable = contentDiv.children("table");
var gridDivWidth = contentDiv.width() - kendo.support.scrollbar();
masterHeaderTable.width("");
masterBodyTable.width("");
var headerWidth = getMasterColumnsWidth(masterHeaderTable),
lastHeaderColElement = grid.thead.parent().find("col").last(),
lastDataColElement = grid.tbody.parent().children("colgroup").find("col").last(),
delta = parseInt(gridDivWidth, 10) - parseInt(headerWidth, 10);
if (delta > 0) {
delta = Math.abs(delta);
lastHeaderColElement.width(delta);
lastDataColElement.width(delta);
} else {
lastHeaderColElement.width(0);
lastDataColElement.width(0);
}
contentDiv.scrollLeft(contentDiv.scrollLeft() - 1);
contentDiv.scrollLeft(contentDiv.scrollLeft() + 1);
}
$("#grid1").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
},
pageSize: 6,
serverPaging: true,
serverSorting: true
},
height: 430,
pageable: true,
resizable: true,
columnResize: adjustLastColumn,
dataBound: adjustLastColumn,
columns: [{
field: "FirstName",
title: "First Name",
width: "100px"
}, {
field: "LastName",
title: "Last Name",
width: "150px"
}, {
field: "Country",
width: "100px"
}, {
field: "City",
width: "100px"
}, {
field: "Title",
width: "200px"
}, {
template: " "
}]
});
</script>

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.

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

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/

KendoUI Grid Filter Posts Twice

I have this grid with a custom multi-select filter. When I click the filter icon an AJAX method calls an API to grab filter values. The method call is defined in the DocType column.
Here is my grid builder function:
$("#attachmentsGrid").kendoGrid({
pageable: {
change: function() {
CH.RelatedItems.GridPager();
}
},
scrollable: false,
sortable: true,
dataSource: attachments,
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to",
contains: "Contains",
}
}
},
columns:
[
{
title: "id",
field: "Id", //turns out this needs to be lower case
sortable: false,
filterable: false,
template: "<input name='cbCheckboxColumn' type='checkbox' onclick='CH.RelatedItems.ToggleAttachmentsByCheckboxColumn()' data-row='#: Id#' />",
headerTemplate: "<input id='cbCheckboxHeader' type='checkbox' onclick='CH.RelatedItems.ToggleAttachmentsByCheckboxHeader()'",
width: "18px",
},
{
title: "Exists?",
field: "IsAlreadyAttached",
type: "boolean",
sortable: false,
template: "<div style='text-align: center'>#: IsAlreadyAttached #</div>",
filterable: false,
width: "110px",
},
{
title: "Icon",
field: "DocType",
sortable: true,
template: "<div style='text-align: center'><img src='" + config.SPHostUrl + "/_layouts/images/#: DocIcon #' /></div>",
width: "60px",
filterable: {
ui: CH.RelatedItems.AttachmentsIconFilter,
extra: false,
},
},
{
title: "File Name",
field: "Name",
sortable: true,
filterable: false,
template: "<a href='#: Url#' target='_blank'>#: Name#</a>",
width: "650px",
},
{
title: "Modified",
field: "LastModifiedDateOnly",
template: "<span>#: LastModified#</span>",
sortable: true,
width: "250px",
filterable: {
ui: CH.RelatedItems.AttachmentsDateFilter,
extra: false
}
},
],
dataBound: CH.RelatedItems.PostGridDataBound
});
The AttachmentsIconFilter function is here:
pub.AttachmentsIconFilter = function (element) {
var menu = $(element).parent();
menu.find(".k-filter-help-text").text("Show document types:");
menu.find("[data-role=dropdownlist]").remove();
var multiSelect = element.kendoMultiSelect({
dataSource: {
transport: {
read: {
datatype: "jsonp",
url: config.WorkPaperViewRelativePath + "/_RelatedItemsPopup/GetAttachmentsUniqueDocIcons/" + config.SPQueryString
}
}
},
}).data("kendoMultiSelect");
menu.find("[type=submit]").on("click", { widget: multiSelect }, CH.RelatedItems.AttachmentsFilterByIcon);
}
When the AttachmentsIconFilter runs, the AJAX call get made twice:
Kendo Double GET
I thought that the property: filter: { extra: false } was supposed to prevent this double GET?
Also, when I select my filters and the grid make a new request to get the filtered records, it does a double POST. The function for the call to filter the grid is here:
pub.AttachmentsFilterByIcon = function (e) {
var icons = e.data.widget.value();
var filter = { logic: "or", filters: [] };
for (var i = 0; i < icons.length; i++)
{
filter.filters.push({ field: "DocIcon", operator: "Contains", value: icons[i].Contains });
}
$("#attachmentsGrid").data("kendoGrid").dataSource.filter(filter);
}
Any help here? What am I missing?

How to maintain checkbox selection while reloading the JQuery Grid?

I have a JQuery grid which I am reloading everytime when some event occurs on the server (i.e. update in the data set) and display the latest set of data in the grid. This grid has also got checkboxes in it's first column. What's happening is let's say user is selecting some checkboxes and in the meantime if the grid gets reloaded due to update in the data on the server, my grid gets reloaded with the latest set of data but all my previous checkbox selection gets lost. How can I mark these selected checkboxes again after grid reload?
Please suggest.
function PushData() {
// creates a proxy to the Alarm hub
var alarm = $.connection.alarmHub;
alarm.notification = function () {
$("#jqTable").trigger("reloadGrid",[{current:true}]);
};
// Start the connection and request current state
$.connection.hub.start(function () {
BindGrid();
});
}
function BindGrid() {
jqDataUrl = "Alarm/LoadjqData";
var selectedRowIds;
$("#jqTable").jqGrid({
url: jqDataUrl,
cache: false,
datatype: "json",
mtype: "POST",
multiselect: true ,
postData: {
sp: function () { return getPriority(); },
},
colNames: ["Id", "PointRef", "Value", "State", "Ack State", "Priority", "AlarmDate", "", ""],
colModel: [
//{ name: 'alarmId_Checkbox', index: 'chekbox', width: 100, formatter: "checkbox", formatoptions: { disabled: false }, editable: true, edittype: "checkbox" },
{ name: "AlarmId", index: "AlarmId", width: 70, align: "left" },
{ name: "PointRef", index: "PointRef", width: 200, align: "left" },
{ name: "Value", index: "Value", width: 120, align: "left" },
{ name: "AlarmStateName", index: "AlarmStateName", width: 150, align: "left" },
{ name: "AcknowledgementStateName", index: "AcknowledgementStateName", width: 200, align: "left" },
{ name: "Priority", index: "Priority", width: 130, align: "left" },
{ name: "AlarmDate", index: "AlarmDate", width: 250, align: "left" },
{ name: "TrendLink", index: "Trends", width: 100, align: "left" },
{ name: "MimicsLink", index: "Mimics", width: 100, align: "left" }
],
// Grid total width and height
width: 710,
height: 500,
hidegrid: false,
// Paging
toppager: false,
pager: $("#jqTablePager"),
rowNum: 20,
rowList: [5, 10, 20],
viewrecords: true, // "total number of records" is displayed
// Default sorting
sortname: "Priority",
sortorder: "asc",
// Grid caption
caption: "Telemetry Alarms",
onCellSelect: function (rowid, icol, cellcontent, e) {
var cm = jQuery("#jqTable").jqGrid('getGridParam', 'colModel');
var colName = cm[icol];
//alert(colName['index']);
if (colName['index'] == 'AlarmId') {
if ($("#AlarmDialog").dialog("isOpen")) {
$("#AlarmDialog").dialog("close");
}
AlarmDialogScript(rowid)
}
else if (colName['index'] == 'Trends') {
TrendDialogScript(rowid)
}
else if (colName['index'] == 'Mimics') {
MimicsDialogScript(rowid)
}
else {
$("#jqTable").setCell(rowid, "alarmId_Checkbox", true); //Selects checkbox while clicking any other column in the grid
}
},
recreateFilter: true,
emptyrecords: 'No Alarms to display',
loadComplete: function () {
var rowIDs = jQuery("#jqTable").getDataIDs();
for (var i = 0; i < rowIDs.length; i++) {
rowData = jQuery("#jqTable").getRowData(rowIDs[i]);
//change the style of hyperlink coloumns
$("#jqTable").jqGrid('setCell', rowIDs[i], "AlarmId", "", { 'text-decoration': 'underline', 'cursor': 'pointer' });
$("#jqTable").jqGrid('setCell', rowIDs[i], "TrendLink", "", { 'text-decoration': 'underline', 'cursor': 'pointer' });
$("#jqTable").jqGrid('setCell', rowIDs[i], "MimicsLink", "", { 'text-decoration': 'underline', 'cursor': 'pointer' });
if ($.trim(rowData.AcknowledgementStateName) == 'Active') {
$("#jqTable").jqGrid('setCell', rowIDs[i], "AcknowledgementStateName", "", { 'background-color': 'red', 'color': 'white' });
}
else if ($.trim(rowData.AcknowledgementStateName) == 'Acknowledged') {
$("#jqTable").jqGrid('setCell', rowIDs[i], "AcknowledgementStateName", "", { 'background-color': 'Navy', 'color': 'white' });
}
}
//$("#jqTable").jqGrid('hideCol', "AlarmId") //code for hiding a particular column
},
gridComplete: function () {
$('#jqTable input').bind('mouseover', function () {
var tr = $(this).closest('tr');
if ($("#AlarmDialog").dialog("isOpen")) {
$("#AlarmDialog").dialog("close");
}
AlarmDialogScript(tr[0].id);
}
);
}
}).navGrid("#jqTablePager",
{ refresh: true, add: false, edit: false, del: false },
{}, // settings for edit
{}, // settings for add
{}, // settings for delete
{sopt: ["cn"]} // Search options. Some options can be set on column level
)
.trigger('reloadGrid', [{page:1, current:true}]);
}
If I understand you correct you need just use additional parameter i
$("#list").trigger("reloadGrid", [{current:true}]);
or
$("#list").trigger("reloadGrid", [{page: 1, current: true}]);
(See the answer). It do almost the same what Justin suggested.
Depend from what you want exactly mean under reloading of the grid it can be that waht you need is to save the grid state inclusive the list of selected items in localStorage and reload the state after loading the grid. This answer describes in details the implementation. The corresponding demo from the answer could be simplified using new jqGrid events which are introduced in version 4.3.2.
You could save the selections before reloading the grid, for example in the beforeRequest event:
selectedRowIDs = jQuery('#myGrid').getGridParam('selarrrow');
Then after the grid has been reloaded, you can loop over selectedRowIDs and reselect each one using setSelection. For example:
for (i = 0, count = selectedRowIDs.length; i < count; i++) {
jQuery('#myGrid').jqGrid('setSelection', selectedRowIDs[i], false);
}
You might run this code in the loadComplete event.
use
recreateFilter: true
and you should be done

Resources