grid.celledit.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*jshint eqeqeq:false */
  2. /*global jQuery */
  3. (function($){
  4. /*
  5. **
  6. * jqGrid extension for cellediting Grid Data
  7. * Tony Tomov tony@trirand.com
  8. * http://trirand.com/blog/
  9. * Dual licensed under the MIT and GPL licenses:
  10. * http://www.opensource.org/licenses/mit-license.php
  11. * http://www.gnu.org/licenses/gpl-2.0.html
  12. **/
  13. /**
  14. * all events and options here are aded anonynous and not in the base grid
  15. * since the array is to big. Here is the order of execution.
  16. * From this point we use jQuery isFunction
  17. * formatCell
  18. * beforeEditCell,
  19. * onSelectCell (used only for noneditable cels)
  20. * afterEditCell,
  21. * beforeSaveCell, (called before validation of values if any)
  22. * beforeSubmitCell (if cellsubmit remote (ajax))
  23. * afterSubmitCell(if cellsubmit remote (ajax)),
  24. * afterSaveCell,
  25. * errorCell,
  26. * serializeCellData - new
  27. * Options
  28. * cellsubmit (remote,clientArray) (added in grid options)
  29. * cellurl
  30. * ajaxCellOptions
  31. * */
  32. "use strict";
  33. $.jgrid.extend({
  34. editCell : function (iRow,iCol, ed){
  35. return this.each(function (){
  36. var $t = this, nm, tmp,cc, cm;
  37. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  38. iCol = parseInt(iCol,10);
  39. // select the row that can be used for other methods
  40. $t.p.selrow = $t.rows[iRow].id;
  41. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  42. // check to see if we have already edited cell
  43. if ($t.p.savedRow.length>0) {
  44. // prevent second click on that field and enable selects
  45. if (ed===true ) {
  46. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  47. return;
  48. }
  49. }
  50. // save the cell
  51. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  52. } else {
  53. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},1);
  54. }
  55. cm = $t.p.colModel[iCol];
  56. nm = cm.name;
  57. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  58. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  59. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  60. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  61. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  62. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  63. }
  64. $(cc).addClass("edit-cell ui-state-highlight");
  65. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  66. try {
  67. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  68. } catch (_) {
  69. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html();
  70. }
  71. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  72. if (!cm.edittype) {cm.edittype = "text";}
  73. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  74. if(tmp === " " || tmp === " " || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  75. if($.isFunction($t.p.formatCell)) {
  76. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  77. if(tmp2 !== undefined ) {tmp = tmp2;}
  78. }
  79. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  80. if ($.isFunction($t.p.beforeEditCell)) {
  81. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  82. }
  83. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm,rowId: $t.rows[iRow].id});
  84. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  85. $(cc).html("").append(elc).attr("tabindex","0");
  86. $.jgrid.bindEv.call($t, elc, opt);
  87. window.setTimeout(function () { $(elc).focus();},1);
  88. $("input, select, textarea",cc).bind("keydown",function(e) {
  89. if (e.keyCode === 27) {
  90. if($("input.hasDatepicker",cc).length >0) {
  91. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  92. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  93. } else {
  94. $($t).jqGrid("restoreCell",iRow,iCol);
  95. }
  96. } //ESC
  97. if (e.keyCode === 13 && !e.shiftKey) {
  98. $($t).jqGrid("saveCell",iRow,iCol);
  99. // Prevent default action
  100. return false;
  101. } //Enter
  102. if (e.keyCode === 9) {
  103. if(!$t.grid.hDiv.loading ) {
  104. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  105. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  106. } else {
  107. return false;
  108. }
  109. }
  110. e.stopPropagation();
  111. });
  112. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  113. if ($.isFunction($t.p.afterEditCell)) {
  114. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  115. }
  116. } else {
  117. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  118. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  119. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  120. }
  121. cc.addClass("edit-cell ui-state-highlight");
  122. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  123. tmp = cc.html().replace(/\&#160\;/ig,'');
  124. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  125. if ($.isFunction($t.p.onSelectCell)) {
  126. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  127. }
  128. }
  129. $t.p.iCol = iCol; $t.p.iRow = iRow;
  130. });
  131. },
  132. saveCell : function (iRow, iCol){
  133. return this.each(function(){
  134. var $t= this, fr;
  135. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  136. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  137. if(fr !== null) {
  138. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  139. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  140. switch (cm.edittype) {
  141. case "select":
  142. if(!cm.editoptions.multiple) {
  143. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  144. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  145. } else {
  146. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  147. v = $(sel).val();
  148. if(v) { v.join(",");} else { v=""; }
  149. $("option:selected",sel).each(
  150. function(i,selected){
  151. selectedText[i] = $(selected).text();
  152. }
  153. );
  154. v2 = selectedText.join(",");
  155. }
  156. if(cm.formatter) { v2 = v; }
  157. break;
  158. case "checkbox":
  159. var cbv = ["Yes","No"];
  160. if(cm.editoptions){
  161. cbv = cm.editoptions.value.split(":");
  162. }
  163. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  164. v2=v;
  165. break;
  166. case "password":
  167. case "text":
  168. case "textarea":
  169. case "button" :
  170. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  171. v2=v;
  172. break;
  173. case 'custom' :
  174. try {
  175. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  176. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  177. if (v===undefined) { throw "e2";} else { v2=v; }
  178. } else { throw "e1"; }
  179. } catch (e) {
  180. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  181. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  182. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  183. }
  184. break;
  185. }
  186. // The common approach is if nothing changed do not do anything
  187. if (v2 !== $t.p.savedRow[fr].v){
  188. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  189. if (vvv) {v = vvv; v2=vvv;}
  190. if ($.isFunction($t.p.beforeSaveCell)) {
  191. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  192. if (vv) {v = vv; v2=vv;}
  193. }
  194. var cv = $.jgrid.checkValues.call($t,v,iCol);
  195. if(cv[0] === true) {
  196. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  197. if ($.isFunction($t.p.beforeSubmitCell)) {
  198. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  199. if (!addpost) {addpost={};}
  200. }
  201. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  202. if ($t.p.cellsubmit === 'remote') {
  203. if ($t.p.cellurl) {
  204. var postdata = {};
  205. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  206. postdata[nm] = v;
  207. var idname,oper, opers;
  208. opers = $t.p.prmNames;
  209. idname = opers.id;
  210. oper = opers.oper;
  211. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  212. postdata[oper] = opers.editoper;
  213. postdata = $.extend(addpost,postdata);
  214. $($t).jqGrid("progressBar", {method:"show", loadtype : $t.p.loadui, htmlcontent: $.jgrid.defaults.savetext || "Saving..." });
  215. $t.grid.hDiv.loading = true;
  216. $.ajax( $.extend( {
  217. url: $t.p.cellurl,
  218. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  219. type: "POST",
  220. complete: function (result, stat) {
  221. $($t).jqGrid("progressBar", {method:"hide", loadtype : $t.p.loadui });
  222. $t.grid.hDiv.loading = false;
  223. if (stat === 'success') {
  224. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  225. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  226. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  227. }
  228. if(ret[0] === true){
  229. $(cc).empty();
  230. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  231. $(cc).addClass("dirty-cell");
  232. $($t.rows[iRow]).addClass("edited");
  233. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  234. if ($.isFunction($t.p.afterSaveCell)) {
  235. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  236. }
  237. $t.p.savedRow.splice(0,1);
  238. } else {
  239. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  240. $($t).jqGrid("restoreCell",iRow,iCol);
  241. }
  242. }
  243. },
  244. error:function(res,stat,err) {
  245. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  246. $t.grid.hDiv.loading = false;
  247. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  248. if ($.isFunction($t.p.errorCell)) {
  249. $t.p.errorCell.call($t, res,stat,err);
  250. $($t).jqGrid("restoreCell",iRow,iCol);
  251. } else {
  252. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  253. $($t).jqGrid("restoreCell",iRow,iCol);
  254. }
  255. }
  256. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  257. } else {
  258. try {
  259. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  260. $($t).jqGrid("restoreCell",iRow,iCol);
  261. } catch (e) {}
  262. }
  263. }
  264. if ($t.p.cellsubmit === 'clientArray') {
  265. $(cc).empty();
  266. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  267. $(cc).addClass("dirty-cell");
  268. $($t.rows[iRow]).addClass("edited");
  269. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  270. if ($.isFunction($t.p.afterSaveCell)) {
  271. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  272. }
  273. $t.p.savedRow.splice(0,1);
  274. }
  275. } else {
  276. try {
  277. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  278. $($t).jqGrid("restoreCell",iRow,iCol);
  279. } catch (e) {}
  280. }
  281. } else {
  282. $($t).jqGrid("restoreCell",iRow,iCol);
  283. }
  284. }
  285. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  286. });
  287. },
  288. restoreCell : function(iRow, iCol) {
  289. return this.each(function(){
  290. var $t= this, fr;
  291. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  292. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  293. if(fr !== null) {
  294. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  295. // datepicker fix
  296. if($.isFunction($.fn.datepicker)) {
  297. try {
  298. $("input.hasDatepicker",cc).datepicker('hide');
  299. } catch (e) {}
  300. }
  301. $(cc).empty().attr("tabindex","-1");
  302. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  303. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  304. if ($.isFunction($t.p.afterRestoreCell)) {
  305. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  306. }
  307. $t.p.savedRow.splice(0,1);
  308. }
  309. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  310. });
  311. },
  312. nextCell : function (iRow,iCol) {
  313. return this.each(function (){
  314. var $t = this, nCol=false, i;
  315. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  316. // try to find next editable cell
  317. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  318. if ( $t.p.colModel[i].editable ===true) {
  319. nCol = i; break;
  320. }
  321. }
  322. if(nCol !== false) {
  323. $($t).jqGrid("editCell",iRow,nCol,true);
  324. } else {
  325. if ($t.p.savedRow.length >0) {
  326. $($t).jqGrid("saveCell",iRow,iCol);
  327. }
  328. }
  329. });
  330. },
  331. prevCell : function (iRow,iCol) {
  332. return this.each(function (){
  333. var $t = this, nCol=false, i;
  334. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  335. // try to find next editable cell
  336. for (i=iCol-1; i>=0; i--) {
  337. if ( $t.p.colModel[i].editable ===true) {
  338. nCol = i; break;
  339. }
  340. }
  341. if(nCol !== false) {
  342. $($t).jqGrid("editCell",iRow,nCol,true);
  343. } else {
  344. if ($t.p.savedRow.length >0) {
  345. $($t).jqGrid("saveCell",iRow,iCol);
  346. }
  347. }
  348. });
  349. },
  350. GridNav : function() {
  351. return this.each(function () {
  352. var $t = this;
  353. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  354. // trick to process keydown on non input elements
  355. $t.p.knv = $t.p.id + "_kn";
  356. var selection = $("<div style='position:fixed;top:0px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+$t.p.knv+"'></div></div>"),
  357. i, kdir;
  358. function scrollGrid(iR, iC, tp){
  359. if (tp.substr(0,1)==='v') {
  360. var ch = $($t.grid.bDiv)[0].clientHeight,
  361. st = $($t.grid.bDiv)[0].scrollTop,
  362. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  363. pROT = $t.rows[iR].offsetTop;
  364. if(tp === 'vd') {
  365. if(nROT >= ch) {
  366. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  367. }
  368. }
  369. if(tp === 'vu'){
  370. if (pROT < st ) {
  371. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  372. }
  373. }
  374. }
  375. if(tp==='h') {
  376. var cw = $($t.grid.bDiv)[0].clientWidth,
  377. sl = $($t.grid.bDiv)[0].scrollLeft,
  378. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  379. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  380. if(nCOL >= cw+parseInt(sl,10)) {
  381. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  382. } else if (pCOL < sl) {
  383. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  384. }
  385. }
  386. }
  387. function findNextVisible(iC,act){
  388. var ind, i;
  389. if(act === 'lft') {
  390. ind = iC+1;
  391. for (i=iC;i>=0;i--){
  392. if ($t.p.colModel[i].hidden !== true) {
  393. ind = i;
  394. break;
  395. }
  396. }
  397. }
  398. if(act === 'rgt') {
  399. ind = iC-1;
  400. for (i=iC; i<$t.p.colModel.length;i++){
  401. if ($t.p.colModel[i].hidden !== true) {
  402. ind = i;
  403. break;
  404. }
  405. }
  406. }
  407. return ind;
  408. }
  409. $(selection).insertBefore($t.grid.cDiv);
  410. $("#"+$t.p.knv)
  411. .focus()
  412. .keydown(function (e){
  413. kdir = e.keyCode;
  414. if($t.p.direction === "rtl") {
  415. if(kdir===37) { kdir = 39;}
  416. else if (kdir===39) { kdir = 37; }
  417. }
  418. switch (kdir) {
  419. case 38:
  420. if ($t.p.iRow-1 >0 ) {
  421. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  422. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  423. }
  424. break;
  425. case 40 :
  426. if ($t.p.iRow+1 <= $t.rows.length-1) {
  427. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  428. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  429. }
  430. break;
  431. case 37 :
  432. if ($t.p.iCol -1 >= 0) {
  433. i = findNextVisible($t.p.iCol-1,'lft');
  434. scrollGrid($t.p.iRow, i,'h');
  435. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  436. }
  437. break;
  438. case 39 :
  439. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  440. i = findNextVisible($t.p.iCol+1,'rgt');
  441. scrollGrid($t.p.iRow,i,'h');
  442. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  443. }
  444. break;
  445. case 13:
  446. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  447. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  448. }
  449. break;
  450. default :
  451. return true;
  452. }
  453. return false;
  454. });
  455. });
  456. },
  457. getChangedCells : function (mthd) {
  458. var ret=[];
  459. if (!mthd) {mthd='all';}
  460. this.each(function(){
  461. var $t= this,nm;
  462. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  463. $($t.rows).each(function(j){
  464. var res = {};
  465. if ($(this).hasClass("edited")) {
  466. $('td',this).each( function(i) {
  467. nm = $t.p.colModel[i].name;
  468. if ( nm !== 'cb' && nm !== 'subgrid') {
  469. if (mthd==='dirty') {
  470. if ($(this).hasClass('dirty-cell')) {
  471. try {
  472. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  473. } catch (e){
  474. res[nm] = $.jgrid.htmlDecode($(this).html());
  475. }
  476. }
  477. } else {
  478. try {
  479. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  480. } catch (e) {
  481. res[nm] = $.jgrid.htmlDecode($(this).html());
  482. }
  483. }
  484. }
  485. });
  486. res.id = this.id;
  487. ret.push(res);
  488. }
  489. });
  490. });
  491. return ret;
  492. }
  493. /// end cell editing
  494. });
  495. })(jQuery);