Permalink
Browse files

Modify subgrid module to support new event system

  • Loading branch information...
1 parent a1935e8 commit 7d2888310f8b0e55c8d1e3257e72458c93311074 @tonytomov committed Jan 10, 2012
Showing with 19 additions and 15 deletions.
  1. +19 −15 js/grid.subgrid.js
View
@@ -7,6 +7,7 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl-2.0.html
**/
+"use strict";
$.jgrid.extend({
setSubGrid : function () {
return this.each(function (){
@@ -136,7 +137,7 @@ addSubGrid : function( pos, sind ) {
if(ts.p.subGridModel[0].params) {
for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
for(i=0; i<ts.p.colModel.length; i++) {
- if(ts.p.colModel[i].name == ts.p.subGridModel[0].params[j]) {
+ if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
}
}
@@ -160,7 +161,7 @@ addSubGrid : function( pos, sind ) {
dataType:ts.p.subgridtype,
data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
complete: function(sxml) {
- if(ts.p.subgridtype == "xml") {
+ if(ts.p.subgridtype === "xml") {
subGridXml(sxml.responseXML, sid);
} else {
subGridJson($.jgrid.parse(sxml.responseText),sid);
@@ -175,7 +176,7 @@ addSubGrid : function( pos, sind ) {
};
var _id, pID,atd, nhc=0, bfsc, r;
$.each(ts.p.colModel,function(i,v){
- if(this.hidden === true || this.name == 'rn' || this.name == 'cb') {
+ if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
nhc++;
}
});
@@ -186,20 +187,22 @@ addSubGrid : function( pos, sind ) {
}
while(i < len) {
if($(ts.rows[i]).hasClass('jqgrow')) {
- $(ts.rows[i].cells[pos]).bind('click', function(e) {
+ $(ts.rows[i].cells[pos]).bind('click', function() {
var tr = $(this).parent("tr")[0];
r = tr.nextSibling;
if($(this).hasClass("sgcollapsed")) {
pID = ts.p.id;
_id = tr.id;
if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
- bfsc =true;
- if($.isFunction(ts.p.subGridBeforeExpand)) {
+ 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;}
- $(tr).after( "<tr role='row' class='ui-subgrid'>"+atd+"<td class='ui-widget-content subgrid-cell'><span class='ui-icon "+ts.p.subGridOptions.openicon+"'></span></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='ui-widget-content subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'></div></td></tr>" );
+ $(tr).after( "<tr role='row' class='ui-subgrid'>"+atd+"<td class='ui-widget-content subgrid-cell'><span class='ui-icon "+ts.p.subGridOptions.openicon+"'></span></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='ui-widget-content subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'></div></td></tr>" );
+ $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
if( $.isFunction(ts.p.subGridRowExpanded)) {
ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
} else {
@@ -213,18 +216,19 @@ addSubGrid : function( pos, sind ) {
$(ts).jqGrid('setSelection',_id);
}
} else if($(this).hasClass("sgexpanded")) {
- bfsc = true;
- if( $.isFunction(ts.p.subGridRowColapsed)) {
+ bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
+ bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
+ if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
_id = tr.id;
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();
- }
- $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
+ if(ts.p.subGridOptions.reloadOnExpand === true) {
+ $(r).remove(".ui-subgrid");
+ } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
+ $(r).hide();
+ }
+ $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
}
return false;
});

0 comments on commit 7d28883

Please sign in to comment.