Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery Events in jqGrid (still without form editing and tree grid modules) #236

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 18 additions & 21 deletions js/grid.base.js
Expand Up @@ -978,11 +978,13 @@ $.fn.jqGrid = function( pin ) {
formatter = function (rowId, cellval , colpos, rwdat, _act){ formatter = function (rowId, cellval , colpos, rwdat, _act){
var cm = ts.p.colModel[colpos],v; var cm = ts.p.colModel[colpos],v;
if(typeof cm.formatter !== 'undefined') { if(typeof cm.formatter !== 'undefined') {
var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos }; var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos,
colName: (typeof ts.p.colNames !== 'undefined' && typeof ts.p.colNames[colpos] !== 'undefined') ?
ts.p.colNames[colpos] : (typeof cm.label !== 'undefined' ? cm.label : cm.name)};
if($.isFunction( cm.formatter ) ) { if($.isFunction( cm.formatter ) ) {
v = cm.formatter.call(ts,cellval,opts,rwdat,_act); v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
} else if($.fmatter){ } else if($.fmatter){
v = $.fn.fmatter(cm.formatter, cellval,opts, rwdat, _act); v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
} else { } else {
v = cellVal(cellval); v = cellVal(cellval);
} }
Expand Down Expand Up @@ -2336,14 +2338,20 @@ $.fn.jqGrid = function( pin ) {
cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]); cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
cSel = (cSel === false || cSel === 'stop') ? false : true; cSel = (cSel === false || cSel === 'stop') ? false : true;
if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); } if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return this; } if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return; }
if(cSel === true) { if(cSel === true) {
ri = ptr[0].id;
ci = $.jgrid.getCellIndex(td);
tdHtml = $(td).closest("td,th").html();
$(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
if($.isFunction(ts.p.onCellSelect)) {
ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
}
if(ts.p.cellEdit === true) { if(ts.p.cellEdit === true) {
if(ts.p.multiselect && scb){ if(ts.p.multiselect && scb){
$(ts).jqGrid("setSelection",ptr[0].id,true,e); $(ts).jqGrid("setSelection",ptr[0].id,true,e);
} else { } else {
ri = ptr[0].rowIndex; ri = ptr[0].rowIndex;
ci = $.jgrid.getCellIndex(td);
try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {} try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
} }
} else if ( !ts.p.multikey ) { } else if ( !ts.p.multikey ) {
Expand Down Expand Up @@ -2374,18 +2382,7 @@ $.fn.jqGrid = function( pin ) {
$("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id)[ts.p.useProp ? 'prop' : 'attr']("checked", scb); $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ptr[0].id)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
} }
} }
ri = ptr[0].id;
ci = $.jgrid.getCellIndex(td);
tdHtml = $(td).html();
$(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
if($.isFunction(ts.p.onCellSelect)) {
ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
}
//e.stopPropagation();
} }
//else {
return this;
//}
}).bind('reloadGrid', function(e,opts) { }).bind('reloadGrid', function(e,opts) {
if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;} if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
if (opts && opts.current) { if (opts && opts.current) {
Expand Down Expand Up @@ -2732,7 +2729,7 @@ $.jgrid.extend({
res[nm] = $.jgrid.htmlDecode($("span:first",this).html()); res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
} else { } else {
try { try {
res[nm] = $.unformat(this,{rowId:ind.id, colModel:$t.p.colModel[i]},i); res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
} catch (e){ } catch (e){
res[nm] = $.jgrid.htmlDecode($(this).html()); res[nm] = $.jgrid.htmlDecode($(this).html());
} }
Expand Down Expand Up @@ -2794,7 +2791,7 @@ $.jgrid.extend({
$(this.p.colModel).each(function(i){ $(this.p.colModel).each(function(i){
nm = this.name; nm = this.name;
if( data[nm] !== undefined) { if( data[nm] !== undefined) {
lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date(data[nm],this) : data[nm]; lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date.call(t,data[nm],this) : data[nm];
vl = t.formatter( rowid, data[nm], i, data, 'edit'); vl = t.formatter( rowid, data[nm], i, data, 'edit');
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {}; title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
if(t.p.treeGrid===true && nm == t.p.ExpandColumn) { if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
Expand Down Expand Up @@ -2883,7 +2880,7 @@ $.jgrid.extend({
for(i = gi+si+ni; i < t.p.colModel.length;i++){ for(i = gi+si+ni; i < t.p.colModel.length;i++){
cm = t.p.colModel[i]; cm = t.p.colModel[i];
nm = cm.name; nm = cm.name;
lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(data[nm],cm) : data[nm]; lcdata[nm] = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date.call(t,data[nm],cm) : data[nm];
v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data, 'edit'); v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data, 'edit');
prp = t.formatCol(i,1,v, data, rowid, true); prp = t.formatCol(i,1,v, data, rowid, true);
row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_"+nm+"\" "+prp+">"+v+"</td>"; row += "<td role=\"gridcell\" aria-describedby=\""+t.p.id+"_"+nm+"\" "+prp+">"+v+"</td>";
Expand Down Expand Up @@ -3239,7 +3236,7 @@ $.jgrid.extend({
} }
if($t.p.datatype == "local") { if($t.p.datatype == "local") {
var cm = $t.p.colModel[pos], index; var cm = $t.p.colModel[pos], index;
nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date(nData,cm) : nData; nData = cm.formatter && typeof(cm.formatter) === 'string' && cm.formatter == 'date' ? $.unformat.date.call($t,nData,cm) : nData;
index = $t.p._index[rowid]; index = $t.p._index[rowid];
if(typeof index != "undefined") { if(typeof index != "undefined") {
$t.p.data[index][cm.name] = nData; $t.p.data[index][cm.name] = nData;
Expand Down Expand Up @@ -3272,7 +3269,7 @@ $.jgrid.extend({
var ind = $t.rows.namedItem(rowid); var ind = $t.rows.namedItem(rowid);
if(ind) { if(ind) {
try { try {
ret = $.unformat($("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos); ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
} catch (e){ } catch (e){
ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html()); ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
} }
Expand Down Expand Up @@ -3301,7 +3298,7 @@ $.jgrid.extend({
while(i<ln){ while(i<ln){
if($($t.rows[i]).hasClass('jqgrow')) { if($($t.rows[i]).hasClass('jqgrow')) {
try { try {
val = $.unformat($($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos); val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
} catch (e) { } catch (e) {
val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML); val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
} }
Expand Down
6 changes: 3 additions & 3 deletions js/grid.celledit.js
Expand Up @@ -62,7 +62,7 @@ $.jgrid.extend({
$(cc).addClass("edit-cell ui-state-highlight"); $(cc).addClass("edit-cell ui-state-highlight");
$($t.rows[iRow]).addClass("selected-row ui-state-hover"); $($t.rows[iRow]).addClass("selected-row ui-state-hover");
try { try {
tmp = $.unformat(cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol); tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
} catch (_) { } catch (_) {
tmp = ( cm.edittype && cm.edittype == 'textarea' ) ? $(cc).text() : $(cc).html(); tmp = ( cm.edittype && cm.edittype == 'textarea' ) ? $(cc).text() : $(cc).html();
} }
Expand Down Expand Up @@ -467,14 +467,14 @@ $.jgrid.extend({
if (mthd=='dirty') { if (mthd=='dirty') {
if ($(this).hasClass('dirty-cell')) { if ($(this).hasClass('dirty-cell')) {
try { try {
res[nm] = $.unformat(this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i); res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
} catch (e){ } catch (e){
res[nm] = $.jgrid.htmlDecode($(this).html()); res[nm] = $.jgrid.htmlDecode($(this).html());
} }
} }
} else { } else {
try { try {
res[nm] = $.unformat(this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i); res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
} catch (e) { } catch (e) {
res[nm] = $.jgrid.htmlDecode($(this).html()); res[nm] = $.jgrid.htmlDecode($(this).html());
} }
Expand Down
70 changes: 70 additions & 0 deletions js/grid.custom.js
Expand Up @@ -132,6 +132,7 @@ $.jgrid.extend({
p = $.extend({ p = $.extend({
autosearch: true, autosearch: true,
searchOnEnter : true, searchOnEnter : true,
synchronizeToolbar: true,
beforeSearch: null, beforeSearch: null,
afterSearch: null, afterSearch: null,
beforeClear: null, beforeClear: null,
Expand Down Expand Up @@ -282,6 +283,71 @@ $.jgrid.extend({
} }
} }
}; };
var refreshSearchingToolbar = function () {
var $this = $(this), postData, filters, i, l, rules, rule, iCol, cm, cmi, control, tagName,
getColumnIndex = function (grid, columnIndex) {
var cm = grid.jqGrid('getGridParam', 'colModel'), i, l = cm.length;
for (i = 0; i < l; i++) {
if ((cm[i].index || cm[i].name) === columnIndex) {
return i; // return the colModel index
}
}
return -1;
};

if (!this.grid) { return; }

postData = $this.jqGrid('getGridParam', 'postData');
cm = $this.jqGrid('getGridParam', 'colModel');

if (typeof (postData.filters) === "string" &&
typeof (this.ftoolbar) === "boolean" && this.ftoolbar) {
// first clear the searching toolbar
for (i = 0, l = cm.length; i < l; i++) {
control = $("#gs_" + $.jgrid.jqID(cm[i].name));
if (control.length > 0) {
tagName = control[0].tagName.toUpperCase();
if (tagName === "SELECT") { // && cmi.stype === "select"
control.find("option[value='']")
.attr('selected', 'selected');
} else if (tagName === "INPUT") {
control.val('');
}
}
}

filters = $.parseJSON(postData.filters);
if (filters && filters.groupOp === "AND" && typeof (filters.groups) === "undefined") {
// only in case of advance searching without grouping we import filters in the
// searching toolbar
rules = filters.rules;
for (i = 0, l = rules.length; i < l; i++) {
rule = rules[i];
iCol = getColumnIndex($this, rule.field);
if (iCol >= 0) {
cmi = cm[iCol];
control = $("#gs_" + $.jgrid.jqID(cmi.name));
if (control.length > 0 &&
(((typeof (cmi.searchoptions) === "undefined" ||
typeof (cmi.searchoptions.sopt) === "undefined")
&& rule.op === p.defaultSearch) ||
(typeof (cmi.searchoptions) === "object" &&
$.isArray(cmi.searchoptions.sopt) &&
cmi.searchoptions.sopt.length > 0 &&
cmi.searchoptions.sopt[0] === rule.op))) {
tagName = control[0].tagName.toUpperCase();
if (tagName === "SELECT") { // && cmi.stype === "select"
control.find("option[value='" + $.jgrid.jqID(rule.data) + "']")
.attr('selected', 'selected');
} else if (tagName === "INPUT") {
control.val(rule.data);
}
}
}
}
}
}
};
// create the row // create the row
function bindEvents(selector, events) { function bindEvents(selector, events) {
var jElem = $(selector); var jElem = $(selector);
Expand Down Expand Up @@ -431,6 +497,10 @@ $.jgrid.extend({
this.triggerToolbar = triggerToolbar; this.triggerToolbar = triggerToolbar;
this.clearToolbar = clearToolbar; this.clearToolbar = clearToolbar;
this.toggleToolbar = toggleToolbar; this.toggleToolbar = toggleToolbar;
if (p.synchronizeToolbar) {
refreshSearchingToolbar.call($t);
$($t).bind('jqGridLoadComplete.filterToolbar', refreshSearchingToolbar);
}
}); });
}, },


Expand Down
4 changes: 2 additions & 2 deletions js/grid.formedit.js
Expand Up @@ -433,7 +433,7 @@ $.jgrid.extend({
tmp = $("td:eq("+i+")",obj.rows[ind]).text(); tmp = $("td:eq("+i+")",obj.rows[ind]).text();
} else { } else {
try { try {
tmp = $.unformat($("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i); tmp = $.unformat.call(obj,$("td:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
} catch (_) { } catch (_) {
tmp = (this.edittype && this.edittype == "textarea") ? $("td:eq("+i+")",obj.rows[ind]).text() : $("td:eq("+i+")",obj.rows[ind]).html(); tmp = (this.edittype && this.edittype == "textarea") ? $("td:eq("+i+")",obj.rows[ind]).text() : $("td:eq("+i+")",obj.rows[ind]).html();
} }
Expand Down Expand Up @@ -534,7 +534,7 @@ $.jgrid.extend({
tmp = $(this).text(); tmp = $(this).text();
} else { } else {
try { try {
tmp = $.unformat($(this),{rowId:rowid, colModel:cm[i]},i); tmp = $.unformat.call(obj,$(this),{rowId:rowid, colModel:cm[i]},i);
} catch (_) { } catch (_) {
tmp = cm[i].edittype=="textarea" ? $(this).text() : $(this).html(); tmp = cm[i].edittype=="textarea" ? $(this).text() : $(this).html();
} }
Expand Down
2 changes: 1 addition & 1 deletion js/grid.inlinedit.js
Expand Up @@ -60,7 +60,7 @@ $.jgrid.extend({
if(treeg) { tmp = $("span:first",this).html();} if(treeg) { tmp = $("span:first",this).html();}
else { else {
try { try {
tmp = $.unformat(this,{rowId:rowid, colModel:cm[i]},i); tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
} catch (_) { } catch (_) {
tmp = ( cm[i].edittype && cm[i].edittype == 'textarea' ) ? $(this).text() : $(this).html(); tmp = ( cm[i].edittype && cm[i].edittype == 'textarea' ) ? $(this).text() : $(this).html();
} }
Expand Down
6 changes: 3 additions & 3 deletions js/jquery.fmatter.js
Expand Up @@ -55,8 +55,8 @@
var v=cellval; var v=cellval;
opts = $.extend({}, $.jgrid.formatter, opts); opts = $.extend({}, $.jgrid.formatter, opts);


if ($.fn.fmatter[formatType]){ if ($.isFunction($.fn.fmatter[formatType])){
v = $.fn.fmatter[formatType](cellval, opts, rwd, act); v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
} }
return v; return v;
}; };
Expand Down Expand Up @@ -493,7 +493,7 @@
re = /([\.\*\_\'\(\)\{\}\+\?\\])/g, re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat); unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
if(typeof unformatFunc !== 'undefined' && $.isFunction(unformatFunc) ) { if(typeof unformatFunc !== 'undefined' && $.isFunction(unformatFunc) ) {
ret = unformatFunc($(cellval).text(), options, cellval); ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
} else if(!$.fmatter.isUndefined(formatType) && $.fmatter.isString(formatType) ) { } else if(!$.fmatter.isUndefined(formatType) && $.fmatter.isString(formatType) ) {
var opts = $.jgrid.formatter || {}, stripTag; var opts = $.jgrid.formatter || {}, stripTag;
switch(formatType) { switch(formatType) {
Expand Down