jqgrid: subgrid toolbar does not display -
i'm using jqgrid 4.8.2. i'm trying follow along examples on demo site. i've created parent grid , need show subgrid (as grid). reason, toolbar pager subgrid won't display. rownum, width , height options working, though. i've looked @ demo , can't see i'm doing wrong. take @ following code, please?
var lastselection; $(document).ready(function () { $("#jqgrid").jqgrid({ url: 'servlet/getdata', datatype: "json", editurl: "servlet/updateproduct", page: 1, colmodel: [ { label: 'id', name: 'productid', width: 75, key: true }, { label: 'category', name: 'categoryname', width: 90 }, { label: 'name', name: 'productname', width: 100 }, { label: 'country', name: 'country', width: 80 }, { label: 'price', name: 'price', width: 80 }, { label: 'qty', name: 'quantity', width: 80 }, { label: 'included?', name: 'included', width: 80, editable: true, edittype: "checkbox", editoptions: {value:"yes:no"} } ], viewrecords: true, // show current page, data range , total records on toolbar onselectrow: function (rowid) { var grid = $('#jqgrid'); if (rowid && rowid !== lastselection) { grid.jqgrid('restorerow', lastselection); lastselection = rowid; } grid.jqgrid('editrow', lastselection, {keys: true, extraparam : { home: "livonia", productname: function(){ var row = grid.getrowdata(lastselection); // both of these work: var temp = row.productname; var temp1 = row['productname']; return row.productname; } } } ); }, width: 780, height: 200, rownum: 10, pager: "#jqgridpager", subgrid: true, subgridrowexpanded: function(subgrid_id, row_id) { var lastsubgridselection; var grid = $('#jqgrid'); var row = grid.getrowdata(row_id); var productid = row.productid; var subgrid_table_id; subgrid_table_id = subgrid_id + "_t"; jquery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>"); jquery("#"+subgrid_table_id).jqgrid({ url: 'servlet/getproductwarehouses?q=2&id=' + row_id + '&productid=' + productid, datatype: "json", page: 1, colmodel: [ { label: 'product id', name: 'productid', width: 75, key: false, hidden: true }, { label: 'whse id', name: 'whseid', width: 90, key: true }, { label: 'whse name', name: 'whsename', width: 90 }, { label: 'qty', name: 'quantity', width: 80 }, { label: 'included?', name: 'included', width: 80, editable: true, edittype: "checkbox", editoptions: {value:"yes:no"} } ], viewrecords: true, height: '100%', width: 400, rownum: 5, pager: "#jqgridpager" + "_" + subgrid_id }); } }); });
you mean the pager (not toolbar) not displayed in subgrids.
the reason easy if understand how grid subgrid feature works in jqgrid. if add subgrid: true
grid (to main grid) jqgrid insert additional column in colmodel
name "subgrid"
. column have +
icons can used "expand" subgrid. if user clicks on +
icon new row added under row +
icon. row contains <td>
icon , <td>
span on whole grid. last <td>
contains subdrid. before call of subgridrowexpanded
jqgrid creates empty <div>
in cell id constructed grid id, "_" , rowid (of expanding row). first parameter of subgridrowexpanded
callback (subgrid_id
in code) contains id of empty <div>
. picture below shows described above
i marked in red color subgrid row. id of empty div jqgrid_10
in above example because rowid 10
, grid id jqgrid
.
it's important understand have create <table>
element subgrid dynamically inside of subgridrowexpanded
callback. if want subgrid have pager have create <div>
pager too. the problem in code: use pager: "#jqgridpager" + "_" + subgrid_id
option subgrid, don't created <div>
corresponding id.
the next problem: every row (<tr>
) of subgrid have id
attribute (rowid). 1 have assign it. user can open multiple subgrids @ same time. the problem it's possible have id duplicates because of usage same id
in 2 different subgrids or between subgrid , main grid. fix problem id conflicts it's strictly recommended use idprefix
parameter subgrid value different every subgrid.
a possible fixed implementation of subgridrowexpanded
following:
subgridrowexpanded: function (subgriddivid, rowid) { var $subgrid = $("<table id='" + subgriddivid + "_t'></table>"), subgridpagerid = subgriddivid + "_p"; $("#" + subgriddivid) .append($subgrid) .append("<div id='" +subgridpagerid + "'></div>"); $subgrid.jqgrid({ url: 'servlet/getproductwarehouses', postdata: { q: 2, id: rowid, productid: rowid }, datatype: "local", colmodel: [ { label: 'product id', name: 'productid', width: 75, hidden: true }, { label: 'whse id', name: 'whseid', width: 90, key: true }, { label: 'whse name', name: 'whsename', width: 90 }, { label: 'qty', name: 'quantity', width: 80 }, { label: 'included?', name: 'included', width: 80, editable: true, edittype: "checkbox", editoptions: {value:"yes:no"} } ], viewrecords: true, height: '100%', width: 400, rownum: 5, //idprefix: subgriddivid + "_", idprefix: rowid + "_", pager: "#" + subgridpagerid }); }
by way use key: true
property column productid
of main grid. rowid of main grid same productid
. because of used productid: rowid
in above code. 1 more remark. used idprefix: rowid + "_"
subgrid. 1 can use other values in same way, example idprefix: subgriddivid + "_"
.
Comments
Post a Comment