/*jshint eqeqeq:false */ /*global jQuery, define */ (function( factory ) { "use strict"; if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define([ "jquery", "./grid.base" ], factory ); } else { // Browser globals factory( jQuery ); } }(function( $ ) { "use strict"; //module begin $.jgrid.extend({ setSubGrid : function () { return this.each(function (){ var $t = this, cm, i, classes = $.jgrid.styleUI[($t.p.styleUI || 'jQueryUI')].subgrid, suboptions = { plusicon : classes.icon_plus, minusicon : classes.icon_minus, openicon: classes.icon_open, expandOnLoad: false, delayOnLoad : 50, selectOnExpand : false, selectOnCollapse : false, reloadOnExpand : true }; $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {}); $t.p.colNames.unshift(""); $t.p.colModel.unshift({name:'subgrid',width: $.jgrid.cell_width ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true}); cm = $t.p.subGridModel; if(cm[0]) { cm[0].align = $.extend([],cm[0].align || []); for(i=0;i"; }, addSubGrid : function( pos, sind ) { return this.each(function(){ var ts = this; if (!ts.grid ) { return; } var base = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].base, common = $.jgrid.styleUI[(ts.p.styleUI || 'jQueryUI')].common; //------------------------- var subGridCell = function(trdiv,cell,pos) { var tddiv = $("").html(cell); $(trdiv).append(tddiv); }; var subGridXml = function(sjxml, sbid){ var tddiv, i, sgmap, dummy = $("
"), trdiv = $(""); for (i = 0; i"); $(tddiv).html(ts.p.subGridModel[0].name[i]); $(tddiv).width( ts.p.subGridModel[0].width[i]); $(trdiv).append(tddiv); } $(dummy).append(trdiv); if (sjxml){ sgmap = ts.p.xmlReader.subgrid; $(sgmap.root+" "+sgmap.row, sjxml).each( function(){ trdiv = $(""); if(sgmap.repeatitems === true) { $(sgmap.cell,this).each( function(i) { subGridCell(trdiv, $(this).text() || ' ',i); }); } else { var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name; if (f) { for (i=0;i"), trdiv = $(""); for (i = 0; i"); $(tddiv).html(ts.p.subGridModel[0].name[i]); $(tddiv).width( ts.p.subGridModel[0].width[i]); $(trdiv).append(tddiv); } $(dummy).append(trdiv); if (sjxml){ sgmap = ts.p.jsonReader.subgrid; result = $.jgrid.getAccessor(sjxml, sgmap.root); if ( result !== undefined ) { for (i=0;i"); if(sgmap.repeatitems === true) { if(sgmap.cell) { cur=cur[sgmap.cell]; } for (j=0;j 0) { i = sind; len = sind+1; } while(i < len) { if($(ts.rows[i]).hasClass('jqgrow')) { if(ts.p.scroll) { $(ts.rows[i].cells[pos]).unbind('click'); } $(ts.rows[i].cells[pos]).bind('click', function() { var tr = $(this).parent("tr")[0]; pID = ts.p.id; _id = tr.id; $r = $("#" + pID + "_" + _id + "_expandedContent"); if($(this).hasClass("sgcollapsed")) { bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]); bfsc = (bfsc === false || bfsc === 'stop') ? false : true; if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) { bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id); } if(bfsc === false) {return false;} if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$r.hasClass('ui-subgrid') ) ) { atd = pos >=1 ? " ":""; $(tr).after( ""+atd+"
" ); $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]); if( $.isFunction(ts.p.subGridRowExpanded)) { ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id); } else { populatesubgrid(tr); } } else { $r.show().removeClass("ui-sg-collapsed").addClass("ui-sg-expanded"); } $(this).html("").removeClass("sgcollapsed").addClass("sgexpanded"); if(ts.p.subGridOptions.selectOnExpand) { $(ts).jqGrid('setSelection',_id); } } else if($(this).hasClass("sgexpanded")) { bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]); bfsc = (bfsc === false || bfsc === 'stop') ? false : true; if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) { bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id ); } if(bfsc===false) {return false;} if(ts.p.subGridOptions.reloadOnExpand === true) { $r.remove(".ui-subgrid"); } else if($r.hasClass('ui-subgrid')) { // incase of dynamic deleting $r.hide().addClass("ui-sg-collapsed").removeClass("ui-sg-expanded"); } $(this).html("").removeClass("sgexpanded").addClass("sgcollapsed"); if(ts.p.subGridOptions.selectOnCollapse) { $(ts).jqGrid('setSelection',_id); } } return false; }); } i++; } if(ts.p.subGridOptions.expandOnLoad === true) { $(ts.rows).filter('.jqgrow').each(function(index,row){ $(row.cells[0]).click(); }); } ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);}; ts.subGridJson = function(json,sid) {subGridJson(json,sid);}; }); }, expandSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgcollapsed",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } }); }, collapseSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgexpanded",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } }); }, toggleSubGridRow : function(rowid) { return this.each(function () { var $t = this; if(!$t.grid && !rowid) {return;} if($t.p.subGrid===true) { var rc = $(this).jqGrid("getInd",rowid,true); if(rc) { var sgc = $("td.sgcollapsed",rc)[0]; if(sgc) { $(sgc).trigger("click"); } else { sgc = $("td.sgexpanded",rc)[0]; if(sgc) { $(sgc).trigger("click"); } } } } }); } }); //module end }));