jqgrid: how do I change the layout of the pager? - jqgrid

I'd like to change the layout of the pager, so that the VCR buttons are all grouped together, followed by the Page number input field, then the number of rows drop-down. How would I accomplish this?
Here is the code I'm currently using to display the jqgrid. Its the standard JavaScript code:
$(function(){
$("#" + listName).jqGrid({
url: url,
datatype: 'json',
mtype: 'GET',
colNames: columnNames,
colModel: columnModel,
pager: pagerName,
rowNum: displayRows,
rowList: rowList,
sortname: initSortCol,
sortorder: initSortOrder,
viewrecords: true,
multiselect: multiSelect,
gridview: true,
caption: caption,
height: height,
jsonReader: {
root: 'data',
page: 'currentPage',
total: 'totalPages',
records: 'totalRows',
repeatitems: false,
id: dataModelRowId
}
});
jQuery("#" + listName).jqGrid('navGrid','#' + pagerName,{edit:false,add:false,del:false,search:false});

Example of jqgrid with page number, number of records per page.
Code:
$(document).ready(function(){
//jqGrid
$("#librariesList").jqGrid({
url:'<%=request.getContextPath()%>/Admin/getAllLibraries',
datatype: "json",
colNames:['Id','Edit','Type','Created Date', 'Modified Date', 'Url', 'Use Url'],
colModel:[
{name:'libraryId', index:'libraryId',search:false, width:30,sortable: false,hidden:true},
{name:'libraryId', index:'libraryId',search:false, width:30,sortable: false, formatter: editLink},
{name:'type',index:'type',width:80},
{name:'createdDate',index:'createdDate',width:150},
{name:'modifiedDate',index:'modifiedDate',width:150},
{name:'url',index:'url',width:150},
{name:'useUrl',index:'useUrl',width:50},
],
rowNum:20,
rowList:[10,20,30,40,50],
rownumbers: true,
pager: '#pagerDiv',
sortname: 'createdDate',
viewrecords: true,
sortorder: "asc",
autowidth:'true',
});
$('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
$('.ui-jqgrid-bdiv').css('height', window.innerHeight * .55);
$('#load_librariesList').width("130");
$("#librariesList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false},{},{},{},{closeAfterSearch:true});
$(".inline").colorbox({inline:true, width:"20%"});
});
function editLink(cellValue, options, rowdata, action)
{
return "<a href='<%=request.getContextPath()%>/Admin/editLibrary/"+ rowdata.libraryId + "' class='ui-icon ui-icon-pencil' ></a>";
}
jggrid is displayed like below:

Related

jsonReader 'page' not working in jqGrid

I'm using jqGrid in which i have a jsonReader property and inside that i'm using a function to show the pager of the grid.
My jsonReader page function is working when the grid binds some records. Its not getting called when the grid binds no records. But i have to disable the pager(Previous/Last) when the grid binds no records. Any ideas why?
//Code:
$("#AttachmentsGrid").jqGrid({
url: '#Url.Action("LoadTransactionAttachments", "Home")',
postData: { 'transactionId': selectedRowId },
ajaxGridOptions: { contentType: "application/json" },
hoverrows: false,
datatype: 'json',
hidegrid: false,
rowList: [10, 20, 30],
rownumbers: true,
viewrecords: true,
height: 'auto',
gridview: true,
autoencode: true,
autowidth: true,
shrinkToFit: false,
rowNum: 10,
pager: '#AttachmentsPager',
caption: "Attachments",
colNames: ['AttachmentName'],
colModel: [{ name: 'AttachmentName', index: 'AttachmentName' }],
jsonReader: {
repeatitems: false,
id: 'AttachmentId',
page: function (obj) {
//Not working
if (obj.length == 0) {
return "0";
}
}
}
});
Any help?

JqGrid key:true not working with field having custom formatter

I have a grid with following options where "id" I want to set for a row need to be custom formatted.
There are two columns libCode and matCode.
Combining data of these two I want to create Id for row as follows:-
" ;libCode=[libcode];matCode=[matCode]"
But key=true option is not working with this field having its data set by custom formatter.
It returns the row no. if no xmlmap option is defined, or returns data from xmlmap element from XML response but not what custom formatter sets.
I want to know that why key option is not working and is there any other way I could implement this.
Here is my code for grid:
$(function () {
$("#list").jqGrid({
url: "./TestServlet?operation=RetrieveAll&accept=List",
datatype: "xml",
mtype: "GET",
colNames: ["Lib Code", "Mat Code", "Row Id"],
colModel: [ { name: "libCode", hidden:true, xmlmap:"libCd"},
{ name: "matCode", hidden:true, xmlmap:"matCd"},
{ name: "rowId", formatter:formatName , key:true}
],
xmlReader:{
root:"libs",
row:"lib",
repeatitems: false
},
pager: "#pager",
rowNum: 10,
rownumbers: true,
rowList: [10, 20, 30],
sortname: "libCd",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
loadonce: false,
caption: "Library"
});
});
function formatName(cellValue, options, rowObject)
{
return " ;libCd="+$(rowObject).find('libCd').text()+";matCd="+$(rowObject).find('matCd').text();
}
Set property loadonce to true instead of false i.e. loadonce: true.

jqgrid, alert with arror after failet add record to database

it's my code:
<script type="text/javascript">
var grid = $("#list");
$(function(){
var grid = $("#list");
grid.jqGrid({
url:'grid.php',
datatype: 'xml',
mtype: 'GET',
colNames:['ID sprzętu','Kod sprzętu', 'Właściciel','Konfiguracja'],
colModel :[
{name:'SprzetID', index:'SprzetID', width:90},
{name:'Kod', index:'Kod', width:120, editable: true},
{name:'Wlasciciel', index:'Wlasciciel', width:200, align:'left', editable: true},
{name:'Konfiguracja', index:'Konfiguracja', width:400, align:'left', editable: true},
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'SprzetID',
sortorder: 'asc',
viewrecords: true,
gridview: true,
caption: 'Lista sprzętu'
});
grid.jqGrid('navGrid','#pager',
{add: true, edit: true, del: true, search: true}, //options
{width:400, }, // edit options
{width:400,closeAfterAdd: true, url:'add.php'}, // add options
{reloadAfterSubmit:false}, // del options
{width:600} // search options
);
});
All is great, when adding record to database is correctly, but when for example field "Kod" is duplicate (it's unique field), record can't be add to database... and isn't. I want to display alert with error message, but I can't find in documentation how to do it... I gues,I should use "afterSubmit", but how... I don't know.
Resolved. In add parameters I added code:
afterSubmit: function(response, postdata) {
if(response.responseText != ""){
return [false, response.responseText];
}else{
return [true,"Ok"];
}}

jqGrid Subgrid data not showing up

I have seen the same question being asked but none of them contained an answer that I could use. I am using jqgrid 4.4. The main grid loads data fine, in the subgrid I can see the response from my java controller but not sure how to get it to show up.
function(){
jQuery("#subGrid").jqGrid({
url: CONTEXT_ROOT+"/cartonPremium",
id:'gridtable',
datatype: "json",
height: 190,
jsonReader : {
root: 'gridModel',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false,
id: '0'
},
colNames:['idPremium','Name','Week', 'Departure Region' ],
colModel:[
{name:'idPremium',hidden:false, width:100},
{name:'name',index:'name', width:300},
{name:'sequence',index:'sequence', width:90},
{name:'departureRegion',index:'departureRegion',width:100}
],
hidegrid: false,
rowNum:20,
rowList:[20,40,80],
pager: '#psubGrid',
sortname: 'name',
viewrecords: true,
sortorder: "desc",
multiselect: false,
sortable: true,
autowidth: false,
pagerButtons:true,
navigator:true,
//loadonce: true,
altRows: true,
viewsortcols: [true,'vertical',true],
subGrid: true,
// define the icons in subgrid
subGridOptions: {
"plusicon" : "ui-icon-triangle-1-e",
"minusicon" : "ui-icon-triangle-1-s",
"openicon" : "ui-icon-arrowreturn-1-e"//,
//expand all rows on load
//"expandOnLoad" : true
},
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id+"_t";
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
url:CONTEXT_ROOT+"/premiumCasePackOption?rowId="+row_id,
datatype: "json",
colNames:['idCasePackOptions','cypharecommended','distributorapproved', 'height', 'length','statuscode','weight','width'],
colNames:['idCasePackOptions'],
colModel: [
{name:'idCasePackOptions', width:170,hidden:false}
],
rowNum:8,
pager: pager_id,
sortname: 'idCasePackOptions',
sortorder: "asc",
sortable: true,
height: 400
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:true,del:false});
}
}
);
jQuery("#subGrid").jqGrid('navGrid','#psubGrid',{add:false,edit:false,del:false});
}
);
Here is response from server
{"total":1,"page":1,"gridModel":[{"idCasePackOptions":1},{"idCasePackOptions":2},{"idCasePackOptions":3},{"idCasePackOptions":4},{"idCasePackOptions":5},{"idCasePackOptions":6}],"records":6,"rows":8}
Help!! What am I missing?
I finally got it to working...yipeee!!! the magic that was missing from the subgrid
jsonReader: {
root: 'gridModel',
repeatitems: false
}
So the working version looks like this
$(document).ready(
function(){
jQuery("#subGrid").jqGrid({
url: CONTEXT_ROOT+"/cartonPremium",
id:'gridtable',
datatype: "json",
height: '100%' ,
mtype: 'POST',
jsonReader : {
root: 'gridModel',
page: 'page',
total: 'total',
records: 'records',
repeatitems: false,
id: '0'
},
colNames:['idPremium','Name','Week' ],
colModel:[
{name:'idPremium',hidden:false, width:100},
{name:'name',index:'name', width:300},
{name:'sequence',index:'sequence', width:90}
],
hidegrid: false,
rowNum:20,
rowList:[20,40,80],
pager: '#psubGrid',
sortname: 'name',
viewrecords: true,
sortorder: "desc",
multiselect: false,
sortable: true,
autowidth: false,
pagerButtons:true,
navigator:true,
//loadonce: true,
altRows: true,
viewsortcols: [true,'vertical',true],
subGrid: true,
// define the icons in subgrid
subGridOptions: {
"plusicon" : "ui-icon-triangle-1-e",
"minusicon" : "ui-icon-triangle-1-s",
"openicon" : "ui-icon-arrowreturn-1-e",
"reloadOnExpand" : true
},
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id+"_t";
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
url:CONTEXT_ROOT+"/premiumCasePackOption?rowId="+row_id,
datatype: "json",
mtype: 'POST',
colNames:['idCasePackOptions','cypharecommended','distributorapproved', 'height', 'length','statuscode','weight','width'],
colModel: [
{name:'idCasePackOptions', width:170,hidden:false},
{name:'cypharecommended',index:'cypharecommended', width:170},
{name:'distributorapproved',index:'distributorapproved', width:170},
{name:'height',index:'height', width:100},
{name:'length',index:'length', width:80, align:"right"},
{name:'statuscode',index:'statuscode', width:90, align:"right"},
{name:'weight',index:'weight', width:100,align:"right"},
{name:'width',index:'width', width:100}
],
rowNum:8,
pager: pager_id,
sortname: 'idCasePackOptions',
sortorder: "asc",
viewrecords: true,
sortable: true,
height: '100%' ,
autowidth: true,
jsonReader: {
root: 'gridModel',
repeatitems: false
}
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:true,del:false});
}
}
);
//jQuery("#subGrid").jqGrid('navGrid','#psubGrid',{add:false,edit:false,del:false});
}
);
Your data in the subgrid will not be displayed (as well) if one of your given functions do not exist. So if you make a typo empty lines will be displayed:
afterSave: ReloadSubGrid, onError: UpdateFailed, delOptions:...
...
function ReloadSbuGrid(rowid, response) {
...
}
Typo: ReloadSbuGrid should have been ReloadSubGrid

JqGrid- Expanding Subgrid on page load

I have a Jqgrid with subgrid enabled in my MVC 2 project. Subgrid expands and populates data on the button click. I want to expand and show the subgrid data on page load. So i called exapandSubGridRow method on gridComplete event of the parent grid. Now the problem is, subgrid row is expanded on pageload, but with no data, an empty row appears below the parent grid row. Here is my code, Can anyone help me in fixing the problem.
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/jqgrid/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['SurveyQnGrpId', 'SurveyQnGroup1'],
colModel: [
{ name:'SurveyQnGrpId', index:'SurveyQnGrpId', width:40, align:'left' },
{ name:'SurveyQnGroup1',index: 'SurveyQnGroup1',width: 400,
align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'SurveyQnGrpId',
sortorder: "SurveyQnGroup1",
viewrecords: true,
caption: 'My first grid',
subGrid: true,
subGridUrl: '/jqgrid/InnerGridData/',
subGridModel: [{
name: ['SurveyQnGrpId','SurveyQnId', 'SurveyQn', 'SurveyQnCategory',
'MandatoryQn','RadioOption3'],
width: [10,10, 100, 10, 10,10],
align: ['left', 'left', 'left', 'left'],
params: ['SurveyQnGrpId']
}],
gridComplete: function () {
var rowIds = $("#list").getDataIDs();
$.each(rowIds, function (index, rowId) {
$("#list").expandSubGridRow(rowId);
});
}
});
});
</script>
Thanks in advance,
Ancy
I don't know if this was available at the time this question was asked, but I found there is a subGridOptions property, takes an object. One of the properties in that object is expandOnLoad, which, when set to true, will make rows in the parent grid expand when the grid is loaded:
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/jqgrid/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['SurveyQnGrpId', 'SurveyQnGroup1'],
colModel: [
{ name:'SurveyQnGrpId', index:'SurveyQnGrpId', width:40, align:'left' },
{ name:'SurveyQnGroup1',index: 'SurveyQnGroup1',width: 400,
align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'SurveyQnGrpId',
sortorder: "SurveyQnGroup1",
viewrecords: true,
caption: 'My first grid',
subGrid: true,
subGridOptions: { expandOnLoad: true },
subGridUrl: '/jqgrid/InnerGridData/',
subGridModel: [{
name: ['SurveyQnGrpId','SurveyQnId', 'SurveyQn', 'SurveyQnCategory',
'MandatoryQn','RadioOption3'],
width: [10,10, 100, 10, 10,10],
align: ['left', 'left', 'left', 'left'],
params: ['SurveyQnGrpId']
}],
gridComplete: function () {
var rowIds = $("#list").getDataIDs();
$.each(rowIds, function (index, rowId) {
$("#list").expandSubGridRow(rowId);
});
}
});
});
See: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid

Resources