JQGrid : subgrid as a GRID with a navigation bar - jqgrid

I am using JQGrid and displaying subGrid as a JQGRID itself.
I was wondering if there is a way to display the navigation bar for the subgrid too.
I tried following the way its being done for JQGrid, but in vain.
Thanks in advance!

Make sure that in the subGrid jqGRid function you also set the pager property to the pager id in the subgrid
... subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id)
{
var subgrid_table_id;
var 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>");
$("#" + subgrid_table_id).jqGrid({
url:"ListSub/"+ row_id,
datatype: "json",
colNames: ['Street1','Street2','Street3','Zip','Place','Country'],
colModel:
[
{name:"Street1",index:"Street1",width:80,key:true, editable:true},
{name:"Street2",index:"Street2",width:130, editable:true},
{name:"Street3",index:"Street3",width:80,align:"right", editable:true},
{name:"Zip",index:"Zip",width:80,align:"right", editable:true},
{name:"Place",index:"Place",width:100,align:"right", editable:true},
{name:"Country",index:"Country",width:100,align:"right", editable:true}
],
caption: "Offices",
height: "100%",
rowNum:10,
sortname: 'Street1',
sortorder: "asc",
pager:pager_id
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false,search:false})
}....

subGrid: true,
subGridRowExpanded: function(ParentGridID, rowid) {
var datagridSub, navGrid;
SubGridID = ParentGridID+"_t";
//alert(rowid);
navGrid = "p_"+datagridSub;
$("#"+ParentGridID).html("<table id='"+SubGridID+"' class='scroll'></table><div id='"+PagerID+"' class='scroll'></div>");
jQuery("#"+SubGridID).jqGrid({
url:'service url'+rowid,
datatype: "json",
type: "GET",
colNames: ['Id','MID','VendorCode1','VendorCode2','Percentage'],
width:700,
colModel: [
{name:"id",index:"id",width:30},
{name:"mid",index:"mid",width:30},
{name:"vendorcode1",index:"vendorcode1",width:40},
{name:"vendorcode2",index:"vendorcode2",width:40},
{name:"percentage",index:"percentage",width:70}
],
jsonReader: {
repeatitems: false, // To Bind the Data in Grid, if it is JSON format.
id: "id",
root: function (obj) { return obj; } // To Bind the Data in Grid.
// page: function () { return 1; },
//total: function () { return 1; },
//records: function (obj) { return obj.length; },
},
rowNum:20,
pager: '#PagerID',
sortname: 'num',
sortorder: "asc",
postData: {id: rowid},
height: '120%',
});
}

Related

jqGrid width subgrid pager exceeds main grid width

I hope my title is comprehensive !
I am developing my own personal account with one main grid and one grid as subgrid.
The trouble is that main grid pager is displayed fine, but subgrid pager exceeds the width of grid, such as below :
I don't understand what is wrong.
Here is the subgrid code :
subGridRowExpanded: function(subgrid_id, row_id) {
var rowdata = $("#jqGrid").jqGrid('getRowData',row_id),
catg=rowdata.cg_id,
subgrid_table_id = subgrid_id+"_t",
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).closest("td").attr("colspan", 20)
.css({
borderRight:0,
borderLeft:0,
padding:0
})
.parent().find('td:eq(0)')
.addClass('ui-widget-content')
.addClass('ui-state-highlight')
.css({
borderLeft:0,
borderTop:0
});
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"'></div>");
$("#"+subgrid_table_id).jqGrid({
url:"subc.php?rowid="+row_id+"&catg="+catg,
idPrefix:'s_'+row_id+'_',
datatype: "json",
colNames: ["ID","id_cp","Nom du poste"],
colModel:[
{
name:"su_id",
hidden:true
},
{
name:"id_cg",
hidden:true
},
{
name:"su_name"
}
],
caption:"Liste des postes budgétaires",
hidegrid: false,
gridview: true,
autowidth:true,
shrinkToFit:false,
viewrecords: true,
recordtext: "Postes {0} - {1} of {2}",
emptyrecords: "Aucun poste à afficher",
rownumbers:true,
rownumWidth:40,
altRows:false,
height:"auto",
maxHeight: (23*15),
rowNum: 20,
pager: pager_id,
loadComplete: function(){
$("#gview_"+subgrid_table_id+" .ui-jqgrid-titlebar .ui-jqgrid-title").css({color:'#875', fontWeight:'bold', fontSize:'1.2rem', lineHeight:'1.3rem',marginLeft:'10px'});
}
});
$("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{search:false});
}
I'm sure that's a newbie mistake, and I hope somebody could help me.
Many thanks in advance
Cheers
JiheL

load jqgrid via ajax to dialog search options dropdown don't work

When I use my jqgrid (v.4.6) on page evrything is ok.
When I load jqgrid via ajax to jquery dialog searchoptions dropdown list doesn't work for me.
In jqgrid search box searchoptions dropdown list doesn't work for me either.
$(document).ready(function(){
jQuery("#list_bs").jqGrid({
url:'some.php',
datatype: "json",
height: 450,
width: 1050,
colNames:['FirstName','Name','Date'],
colModel:[
{name:'FirstName',index:'FirstName', width:200, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
{name:'Name',index:'Name', width:200, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
{name:'Date',index:'Date', width:100, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
],
rowNum:50,
rowList : [20,30,50],
loadonce:false,
multiselect : false,
mtype: "GET",
shrinkToFit: false,
rownumbers: true,
gridview: true,
pager: '#pager',
sortname: 'Name',
viewrecords: true,
sortorder: "ASC",
toolbar: [true,"top"],
});
$("#list_bs").jqGrid('navGrid', '#pager_bs',
{
edit:false,
add:false ,
del:false,
},
{},
{},
{},
{
multipleSearch: true,
showQuery: true
}
......
)
});
jQuery("#list_bs").jqGrid('filterToolbar',{ searchOperators: true,stringResult:true, searchOnEnter: false, autosearch: true ,enableClear: false});
try like below this work for me.You have give data in the dropdown in its column model
{
name: 'Name', Name: 'Title', align: 'center', editable: true, editoptions: { readonly: 'readonly' },
stype: 'select',
searchoptions: {
sopt: ['eq','cn'],
dataUrl: //get data from server
buildSelect: function (data) {
var response, s = '<select>', i;
response = jQuery.parseJSON(data);
s += '<option value="0">--Select Book Title--</option>';
if (response && response.length) {
$.each(response, function (i) {
s += '<option value="' + this.Name+ '">' + this.Name+ '</option>';
});
}
return s + '</select>';
}
}
}
I don't need dropdown in toolbar input
My search operator dropdown list doesn't open.
The problem is only when my own jqgrid is loaded by ajax in to jquery dialog.
$( "#my_dialog" ).dialog({
width:'auto',
open: function(event, ui){
$.ajax(
{
url: "some.php",
type: "POST",
data: "is_dialog=true",
error: function(){
},
beforeSend: function(){
$("#loader").show();
},
complete: function(){
$("#loader").hide();
},
success: function( strData ){
$("#dialog_content").html(strData );
}
}
);
},
});
...........
<div id="my_dialog" >
<div id="dialog_content"></div>
</div>

Change edittype on addparam and editparam in JqGrid inline Navigator

I have two dropdowns in jqgrid inline navigator. I want to enable both dropdown only for add mode,and only one dropdown for edit mode.
grid = $("#gridTable");
grid.jqGrid({
colModel: [
{ name: 'empId' , width: "250",editable:true,edittype: 'select',editoptions:{value: {"Emp1","Emp2"}}, formoptions:{ rowpos:1, label: "Emp Id", elmprefix:"(*)"},editrules:{required:true}},
{ name: 'Address' , width: "250",editable:true,edittype: 'select',editoptions:{value: {"Emp Add1","Emp Add2"}}, formoptions:{ rowpos:2, label: "Address", elmprefix:"(*)"},editrules:{required:true}}
],
pager: '#gridTablePager',
colNames:[ 'empId', 'Address'],
rowList:[10,20,50,100,200,500],
datatype: "jsonstring",
datastr: dataInDb,
jsonReader: { repeatitems: false },
viewrecords: true,
height: 300,
ignoreCase: true
});
What code I should add for this?
Could anyone help?
you can do something like this.
grid.jqGrid('inlineNav', "#" + paginator, {
addParams: {
addRowParams: {
url: baseUrl + 'Plantilla/InsertCaracteristicaPlantillaTemp',
mtype: "POST",
oneditfunc: function (rowid) {
InitModel(rowid, 'I');
}
},
editParams: {
url: baseUrl + 'Plantilla/UpdateCaracteristicaPlantillaTemp',
mtype: "POST",
oneditfunc: function (rowid) {
InitModel(rowid, 'U');
}
});
function InitModel(rowid, Operation){
if(Operation == "U")
$("#" + rowid + "_fielName").attr("disabled", true);
}
Now, with that function you can enable and disable fields when you want.

posting row_id with URL: when expanding jqgrid to load subgrid

I m trying to load a jqgrid as a subgrid by posting parent row key (dept_id) to url:'sub_grid_load_dept.php', when expanding grid.
But have no idiea how to do it in a simple way.
here is my code
jQuery("#grid-dept").jqGrid({
url:'grid_load_dept.php',
datatype: "xml",
colNames:['dept id','dept prefix','dept name'],
colModel:[
{name:'dept_id',index:'dept_id', width:200, editable: true},
{name:'dept_prefix',index:'dept_prefix', width:200, editable: true},
{name:'dept_name',index:'dept_name', width:200, editable: true}
],
loadonce:false,
mtype: "POST",
pager: '#grid-dept-pager',
sortname: 'dept_id',
sortorder: "asc",
editable: true,
caption: "department",
editurl:"grid_edit_dept.php",
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id)
{
var subgrid_table_id;
var 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>");
$("#" + subgrid_table_id).jqGrid({
url:'sub_grid_load_dept.php',
datatype: "xml",
colNames: ['id','dept_id','office_id','dept_head','date_from','date_to','remarks'],
colModel:
[
{name:"id",index:"id",width:80,key:true, editable:true},
{name:"dept_id",index:"dept_id",width:130, editable:true},
{name:"office_id",index:"office_id",width:80,align:"right", editable:true},
{name:"dept_head",index:"dept_head",width:80,align:"right", editable:true},
{name:"date_from",index:"date_from",width:100,align:"right", editable:true},
{name:"date_to",index:"date_to",width:100,align:"right", editable:true},
{name:"remarks",index:"remarks",width:100,align:"right", editable:true}
],
caption: "Department Details",
mtype: "POST",
sortname: 'id',
sortorder: "asc",
editable: true,
pager:pager_id,
editurl:"sub_grid_edit_dept.php"
});
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:true,add:true,del:false,search:true,refresh:true})
}
What I mean is how to post 'row_id' in subGridRowExpanded: function(subgrid_id, row_id)
by including in URL: proterty.maybe as an array.
I have found Solution:
[http://stackoverflow.com/questions/12823591/how-to-pass-the-selected-row-id-to-the-subgrids-url-in-jqgrid][1]
Used postDATA:An associative array which appends directly to the url.
postData: {prodcutid: row_id}

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

Resources