yvanui.yvgrid.edit.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /**
  2. * yvan.yvgrid.edit.js
  3. * @author luoyifan
  4. * 2018-07-12
  5. */
  6. 'use strict';
  7. (function ($) {
  8. if (!jqxGrid) {
  9. console.warn('no jqxGrid!!');
  10. return;
  11. }
  12. $.extend($.fn.yvgrid.methods, {
  13. /**
  14. * 标记当前数据行已经被修改过
  15. */
  16. editChanged: function (jq) {
  17. jq.each(function () {
  18. var state = $.data(this, 'yvgrid');
  19. state.editIsChanged = true;
  20. });
  21. },
  22. /**
  23. * 对当前行进行编辑, 返回 true 允许编辑,返回 false 不允许编辑
  24. */
  25. beginEdit: function (jq, opt) {
  26. var $dom = $(jq[0]);
  27. var state = $.data(jq[0], 'yvgrid');
  28. if ($dom.yvgrid('isEditing')) {
  29. //正在编辑中, 如果有修改过值, 就校验,如果失败就返回,成功就继续跳转
  30. if (state.editIsChanged) {
  31. if (!$dom.yvgrid('endEdit')) {
  32. return false;
  33. }
  34. } else {
  35. //取消上次编辑,并继续
  36. $dom.yvgrid('cancelEdit');
  37. }
  38. }
  39. var rowindex;
  40. if ($.type(opt) === 'object' && $.type(opt.rowIndex) === 'number') {
  41. rowindex = opt.rowIndex;
  42. } else {
  43. rowindex = $dom.jqxGrid('getselectedrowindex');
  44. }
  45. if ($.type(rowindex) === 'undefined' || rowindex < 0) {
  46. //当前没有选中任何行
  47. return false;
  48. }
  49. //记录当前正在编辑的行编号
  50. state.editRowIndex = rowindex;
  51. //记录当前这个数据行的数据(因为在 setEditRow 时,会改变数据,取消编辑时,希望能完全还原,所以这里需要保存)
  52. state.editRowData = $.extend({}, $dom.jqxGrid('getrowdata', rowindex));
  53. //记录当前正在编辑行,是否被改动过
  54. state.editIsChanged = false;
  55. $dom.jqxGrid('beginrowedit', rowindex);
  56. if ($.type(opt) === 'object' && $.type(opt.focusField) === 'string' && opt.focusField) {
  57. var $editor = $dom.find('[yv-inline-field=' + opt.focusField + ']');
  58. //自动聚焦到编辑控件上 这里要修改 jqxgrid.edit.js 735行源码
  59. setTimeout(function () {
  60. $editor[0].focus();
  61. }, 25);
  62. } else {
  63. //找到第一个可以编辑的列
  64. setTimeout(function () {
  65. var cols = $dom.jqxGrid('columns').records;
  66. for (var i = 0; i < cols.length; i++) {
  67. if (cols[i].editable) {
  68. var $editor = $dom.find('[yv-inline-field=' + cols[i].datafield + ']');
  69. $editor[0].focus();
  70. return;
  71. }
  72. }
  73. }, 25);
  74. }
  75. return true;
  76. },
  77. /**
  78. * 结束当前编辑行,如果提交成功就返回 true,如果校验失败编辑阶段会维持住并返回 false
  79. */
  80. endEdit: function (jq) {
  81. //尝试提交本行请求
  82. var $dom = $(jq[0]);
  83. var state = $.data(jq[0], 'yvgrid');
  84. var option = state.options;
  85. if (!$dom.yvgrid('isEditing')) {
  86. //没有在编辑阶段就不需要处理
  87. return true;
  88. }
  89. if ($.type(state.editRowIndex) === 'undefined' || state.editRowIndex < 0) {
  90. //当前没有选中任何行
  91. return true;
  92. }
  93. //获取当前编辑数据行
  94. var row = $dom.yvgrid('getEditRowInDataRow');
  95. var columns = $dom.jqxGrid('columns');
  96. var validateSuccess = true;
  97. for (var i = 0; i < columns.records.length; i++) {
  98. var col = columns.records[i];
  99. if (!col.editable || !col.validateeverpresentrowwidgetvalue) {
  100. continue;
  101. }
  102. var validResult = col.validateeverpresentrowwidgetvalue.call(col, col.datafield, row[col.datafield], row);
  103. if ($.type(validResult) === 'object') {
  104. //有校验异常
  105. var $editor = $dom.find('[yv-inline-field=' + col.datafield + ']');
  106. $editor.jqxTooltip({
  107. position: 'bottom',
  108. content: validResult.message
  109. }).jqxTooltip('open');
  110. $editor[0].focus();
  111. validateSuccess = false;
  112. break;
  113. }
  114. }
  115. if (validateSuccess) {
  116. //非正常(可控)状态下的取消编辑,只有在 yvgrid.endEdit 模式下,才能校验通过
  117. state.validatePass = true;
  118. //确认提交行
  119. $dom.jqxGrid('endrowedit', state.editRowIndex, false);
  120. //$dom.jqxGrid('updaterow', rowid, oldRow); //不需要再调这句话,不会毁坏冗余的数据结构
  121. delete state.editRowIndex;
  122. delete state.editRowData;
  123. delete state.validatePass;
  124. return true;
  125. }
  126. return false;
  127. },
  128. /**
  129. * 取消当前编辑行
  130. */
  131. cancelEdit: function (jq) {
  132. return jq.each(function () {
  133. var $dom = $(this);
  134. var state = $.data(this, 'yvgrid');
  135. if (!$dom.yvgrid('isEditing')) {
  136. //没有在编辑阶段就不需要处理
  137. return;
  138. }
  139. if ($.type(state.editRowIndex) === 'undefined' || state.editRowIndex < 0) {
  140. //当前没有选中任何行
  141. return;
  142. }
  143. if (state.editIsChanged) {
  144. //自从上次以来,有编辑过
  145. var rowid = $dom.jqxGrid('getrowid', state.editRowIndex);
  146. //让 dataAdapter 不要通知改变
  147. $dom.jqxGrid('source').isTemporary = true;
  148. //从 state.editRowData 还原数据行(从beginEdit时候就自动记录下来了)
  149. $dom.jqxGrid('updaterow', rowid, state.editRowData);
  150. //让 dataAdapter 不要通知改变
  151. $dom.jqxGrid('source').isTemporary = false;
  152. }
  153. delete state.editRowIndex;
  154. delete state.editRowData;
  155. //因为改动源码,所以 updaterow 不会再自动关闭编辑,需要手动调用
  156. var editcell = $dom.jqxGrid('editcell');
  157. try {
  158. $dom.jqxGrid('endcelledit', editcell.row, editcell.column, true, false);
  159. } catch (e) {
  160. }
  161. });
  162. },
  163. /**
  164. * 对当前添加行,进行重置操作
  165. */
  166. addNewResetAction: function (jq) {
  167. var $dom = $(jq[0]);
  168. var resetbutton = $dom.jqxGrid('addnewrowresetbutton');
  169. resetbutton.trigger('mousedown');
  170. var state = $.data($dom[0], 'yvgrid');
  171. delete state.newRowData;
  172. //跳转到第一个可编辑区域 ensurecellvisible
  173. var $first = $dom.find('[yv-newline-type]').first();
  174. setTimeout(function () {
  175. $first[0].focus();
  176. }, 100);
  177. },
  178. /**
  179. * 对当前添加行,进行添加操作
  180. */
  181. addNewAction: function ($dom) {
  182. var state = $.data($dom[0], 'yvgrid');
  183. var option = state.options;
  184. var addnewrowbutton = $dom.jqxGrid('addnewrowbutton');
  185. addnewrowbutton.trigger('mousedown');
  186. var $newrow = $('#addnewrowtop\\.' + $dom[0].id);
  187. //完成之后,查询是否有操作失败的情况
  188. var $target = $newrow.find('.jqx-input-invalid');
  189. if ($target.length > 0) {
  190. var $this = $target.first();
  191. //显示第一个错误 ensurecellvisible
  192. //var editor = this.addnewrowwidget;
  193. $this.jqxTooltip({
  194. position: 'bottom',
  195. content: $this.attr('title')
  196. }).jqxTooltip('open');
  197. setTimeout(function () {
  198. //跳转到第一个发生异常的区域 ensurecellvisible
  199. $target[0].focus();
  200. }, 100);
  201. return false;
  202. }
  203. return true;
  204. },
  205. /**
  206. * 删除被选中的行
  207. */
  208. deleteSelectedRow: function (jq) {
  209. return jq.each(function () {
  210. var target = this;
  211. var $dom = $(target);
  212. $dom.jqxGrid('beginupdate');
  213. var rowindex = $dom.jqxGrid('getselectedrowindex');
  214. var rowid = $dom.jqxGrid('getrowid', rowindex);
  215. $dom.jqxGrid('deleterow', rowid);
  216. var boundIndex = $dom.jqxGrid('getrowboundindex', rowindex);
  217. $dom.jqxGrid('selectrow', boundIndex);
  218. $dom.jqxGrid('endupdate');
  219. });
  220. },
  221. /**
  222. * 判断当前表格是不是在编辑中
  223. */
  224. isEditing: function ($dom) {
  225. //var editors = $dom.jqxGrid('editors');
  226. //return (editors && Object.getOwnPropertyNames(editors).length > 1);
  227. try {
  228. return $dom.jqxGrid('editcell');
  229. } catch (e) {
  230. return false;
  231. }
  232. },
  233. /**
  234. * 获取当前编辑表格的行id
  235. */
  236. editRowIndex: function (jq) {
  237. var target = jq[0];
  238. var edits = $(target).find('[yv-inline-field]');
  239. if (edits.length <= 0) {
  240. return;
  241. }
  242. return edits.first().attr('yv-inline-row');
  243. },
  244. /**
  245. * 获取当前编辑行数据,包括编辑控件内还未提交的数据,并自动判断当前编辑控件是在编辑行,还是在添加行上
  246. */
  247. getEditRow: function ($dom, sender) {
  248. if (!sender) {
  249. //如果没有指定发送者
  250. if ($dom.yvgrid('isEditing')) {
  251. //如果当前在编辑状态,就取表格编辑框里的数据
  252. return $dom.yvgrid('getEditRowInDataRow');
  253. } else {
  254. //否则取新建行里的数据
  255. return $dom.yvgrid('getPresentRow');
  256. }
  257. }
  258. var $sender = $(sender);
  259. if ($sender.closest('.jqx-grid-cell-add-new-row').length > 0) {
  260. //如果当前编辑单元格,在 presentRow 里就取 presentRow
  261. return $dom.yvgrid('getPresentRow');
  262. }
  263. return $dom.yvgrid('getEditRowInDataRow');
  264. },
  265. /**
  266. * 获取 presentRow 的所有数据(包括正在编辑框里没提交的数据)
  267. */
  268. getPresentRow: function ($dom, row) {
  269. var columns = $dom.jqxGrid('columns');
  270. var state = $.data($dom[0], 'yvgrid');
  271. var data = $.extend({}, state.newRowData);
  272. for (var i = 0; i < columns.records.length; i++) {
  273. var colSetter = columns.records[i];
  274. if ($.type(colSetter.geteverpresentrowwidgetvalue) === 'function') {
  275. data[colSetter.datafield] =
  276. colSetter.geteverpresentrowwidgetvalue.call(this, colSetter.datafield, colSetter.addnewrowwidget);
  277. }
  278. }
  279. return data;
  280. },
  281. /**
  282. * 获取当前编辑行数据,(包括编辑控件内还未提交的数据)
  283. */
  284. getEditRowInDataRow: function (jq) {
  285. var target = jq[0];
  286. var $dom = $(target);
  287. var data = $dom.yvgrid('rowData');
  288. $dom.find('[yv-inline-field]').each(function () {
  289. var $me = $(this);
  290. var colName = $me.attr('yv-inline-field');
  291. switch ($me.attr('yv-inline-xtype')) {
  292. case 'searchbox':
  293. data[colName] = $me.yvsearch('getValue');
  294. break;
  295. case 'datebox':
  296. data[colName] = $me.yvdate('getValue');
  297. break;
  298. case 'numberbox':
  299. data[colName] = $me.yvnumber('getValue');
  300. break;
  301. case 'checkbox':
  302. data[colName] = $me.yvcheck('getValue');
  303. break;
  304. case 'combobox':
  305. data[colName] = $me.jqxComboBox('val');
  306. break;
  307. case 'textbox':
  308. data[colName] = $me.val();
  309. break;
  310. }
  311. });
  312. return data;
  313. },
  314. /**
  315. * 为当前编辑行,设置临时数据
  316. */
  317. setEditRow: function ($dom, row, sender) {
  318. if ($.type(sender) === 'undefined') {
  319. if ($dom.yvgrid('isEditing')) {
  320. return $dom.yvgrid('setEditRowInDataRow', row);
  321. } else {
  322. return $dom.yvgrid('setPresentRow', row);
  323. }
  324. }
  325. var $sender = $(sender);
  326. if ($sender.closest('.jqx-grid-cell-add-new-row').length > 0) {
  327. //如果当前编辑单元格,在 presentRow 里就取 presentRow
  328. return $dom.yvgrid('setPresentRow', row);
  329. }
  330. //如果在 dataRow 里就设置 dataRow
  331. return $dom.yvgrid('setEditRowInDataRow', row);
  332. },
  333. /**
  334. * 为 presentRow 设置临时数据
  335. */
  336. setPresentRow: function (jq, row) {
  337. return jq.each(function () {
  338. var target = this;
  339. var $dom = $(target);
  340. var columns = $dom.jqxGrid('columns');
  341. for (var i = 0; i < columns.records.length; i++) {
  342. var colSetter = columns.records[i];
  343. if (!row.hasOwnProperty(colSetter.datafield)) {
  344. //如果没有要设置本列属性
  345. continue;
  346. }
  347. if ($.type(colSetter.reseteverpresentrowwidgetvalue) === 'function') {
  348. colSetter.reseteverpresentrowwidgetvalue.call(this, colSetter.datafield, colSetter.addnewrowwidget, row[colSetter.datafield]);
  349. }
  350. }
  351. var state = $.data(this, 'yvgrid');
  352. if (!state.newRowData) {
  353. state.newRowData = row;
  354. } else {
  355. $.extend(state.newRowData, row);
  356. }
  357. });
  358. },
  359. /**
  360. * 为当前编辑行,设置临时数据
  361. */
  362. setEditRowInDataRow: function (jq, row) {
  363. return jq.each(function () {
  364. var target = this;
  365. var $dom = $(target);
  366. var state = $.data(target, 'yvgrid');
  367. if (!$dom.yvgrid('isEditing')) {
  368. //如果当前没有进入编辑状态,就取消操作
  369. return;
  370. }
  371. $dom.yvgrid('editChanged');
  372. var rowindex = $dom.yvgrid('editRowIndex');
  373. var rowid = $dom.jqxGrid('getrowid', rowindex);
  374. //找到所有 yv-inline-field 标识的控件,设值到控件中
  375. var setEditorCount = 0; //获取到设置次数
  376. for (var colName in row) {
  377. if (!row.hasOwnProperty(colName)) continue;
  378. var $editor = $dom.find('[yv-inline-field=' + colName + ']');
  379. if ($editor.length <= 0) {
  380. //UI中没有找到编辑控件
  381. continue;
  382. }
  383. switch ($editor.attr('yv-inline-xtype')) {
  384. case 'searchbox':
  385. $editor.yvsearch('setValue', row[colName]);
  386. setEditorCount++;
  387. break;
  388. case 'datebox':
  389. $editor.yvdate('setValue', row[colName]);
  390. setEditorCount++;
  391. break;
  392. case 'numberbox':
  393. $editor.yvnumber('setValue', row[colName]);
  394. setEditorCount++;
  395. break;
  396. case 'checkbox':
  397. $editor.yvcheck('setValue', row[colName]);
  398. setEditorCount++;
  399. break;
  400. case 'combobox':
  401. $editor.jqxComboBox('val', row[colName]);
  402. setEditorCount++;
  403. break;
  404. case 'textbox':
  405. $editor.val(row[colName]);
  406. setEditorCount++;
  407. break;
  408. }
  409. }
  410. //判断如果 setEditors 已经把属性数量都设置好了,就不用再 updaterow,因为 updaterow 会引起延迟
  411. if (setEditorCount < Object.getOwnPropertyNames(row).length) {
  412. //后台设置数据源
  413. var oldRow = $dom.yvgrid('getEditRowInDataRow');
  414. $.extend(oldRow, row);
  415. //让 dataAdapter 不要通知改变
  416. $dom.jqxGrid('source').isTemporary = true;
  417. //更改 jqxgrid.js:3260行 updaterow之后不会关闭当前编辑框
  418. $dom.jqxGrid('updaterow', rowid, oldRow);
  419. //让 dataAdapter 可以接受通知改变
  420. $dom.jqxGrid('source').isTemporary = false;
  421. }
  422. });
  423. },
  424. });
  425. $.fn.yvgrid.edit = {
  426. //在切换之前
  427. beforeSelect: function (event, targetBoundIndex) {
  428. var $dom = $(this);
  429. var state = $.data(this, 'yvgrid');
  430. var option = state.options;
  431. var beginEditOption = undefined;
  432. var isEditing = $dom.yvgrid('isEditing');
  433. if (event.type === 'cellclick') {
  434. //单元格点击
  435. if (option.editOnSelected && event.args.column && event.args.column.editable) {
  436. //鼠标点击后立刻编辑
  437. beginEditOption = {
  438. type: 'cellclick',
  439. rowIndex: event.args.rowindex,
  440. focusField: event.args.column.datafield
  441. };
  442. } else if (isEditing) {
  443. // 如果当前正在编辑
  444. if (state.editIsChanged) {
  445. //如果改过,就返回提交结果
  446. return $dom.yvgrid('endEdit');
  447. }
  448. //没改过,取消编辑状态后,允许跳转
  449. $dom.yvgrid('cancelEdit');
  450. return true;
  451. } else {
  452. //允许跳转
  453. return true;
  454. }
  455. } else {
  456. if (!isEditing) {
  457. //没有编辑, 允许切换
  458. return true;
  459. }
  460. //找到当前焦点所在的单元格
  461. beginEditOption = {
  462. type: event.type,
  463. rowIndex: targetBoundIndex,
  464. focusField: $(event.target).attr('yv-inline-field')
  465. };
  466. }
  467. if (beginEditOption) {
  468. //如果切换编辑行成功,就允许跳转,否则不允许
  469. return $dom.yvgrid('beginEdit', beginEditOption);
  470. }
  471. //其他情况下,正在编辑状态时,不允许跳转
  472. return true;
  473. },
  474. columnOption: function (colOpt, targetOpt) {
  475. if (!colOpt.editor) {
  476. $.extend(targetOpt, {
  477. editable: false,
  478. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  479. htmlElement.addClass('yvgrid-presentrow-disable');
  480. var editor = $("<div class=\"jqx-grid-cell-left-align\" style=\"margin-top: 8.5px;\"></div>").appendTo(htmlElement);
  481. return editor;
  482. },
  483. initEverPresentRowWidget: function (datafield, htmlElement) {
  484. },
  485. getEverPresentRowWidgetValue: function (datafield, htmlElement, validate) {
  486. return htmlElement.html();
  487. },
  488. resetEverPresentRowWidgetValue: function (datafield, htmlElement, value) {
  489. htmlElement.html(value || '');
  490. }
  491. });
  492. return;
  493. }
  494. function validation() {
  495. //非正常状态下的取消编辑,都会被认为是非法的
  496. var state = $.data(this.owner.element, 'yvgrid');
  497. if (state.validatePass === true) {
  498. return true;
  499. }
  500. var $dom = $(this.owner.element);
  501. setTimeout(function () {
  502. var tt = $dom.find('.jqx-grid-validation-arrow-up');
  503. var t2 = tt.next();
  504. tt.remove();
  505. t2.remove();
  506. });
  507. return {result: false, message: ''};
  508. }
  509. targetOpt.editable = true;
  510. switch (colOpt.editor.xtype) {
  511. case 'searchbox': {
  512. $.extend(targetOpt, {
  513. editable: true,
  514. columntype: 'textbox',
  515. validation: validation,
  516. createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
  517. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  518. // 自从第一次被初始化后,防止第二次再进行初始化
  519. if ($.data(editor[0], 'inited')) {
  520. return;
  521. }
  522. $.data(editor[0], 'inited', true);
  523. var $dom = $(this.owner.element);
  524. var opt = $.extend({
  525. height: '100%',
  526. width: '100%',
  527. onChange: function () {
  528. $dom.yvgrid('editChanged');
  529. if ($.type(colOpt.onChange) === 'function') {
  530. colOpt.onChange.apply(this, arguments);
  531. }
  532. }
  533. }, colOpt.editor);
  534. editor.yvsearch(opt);
  535. editor.on('focus', function () {
  536. $dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  537. });
  538. editor.attr('xtype', 'yvsearch');
  539. editor.attr('yv-inline-field', colOpt.field);
  540. editor.attr('yv-inline-xtype', 'searchbox');
  541. editor.attr('yv-inline-row', row);
  542. },
  543. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  544. editor.yvsearch('setValue', cellvalue);
  545. },
  546. geteditorvalue: function (row, cellvalue, editor) {
  547. return editor.yvsearch('getValue');
  548. },
  549. validateeverpresentrowwidgetvalue: function (datafield, value, row, isPresentRow) {
  550. var error = (function () {
  551. if (colOpt.editor.required) {
  552. if ($.trim(value) === '') {
  553. return "必填";
  554. }
  555. }
  556. if ($.type(colOpt.editor.validate) === 'function') {
  557. return colOpt.editor.validate(value, row);
  558. }
  559. })();
  560. if (error) {
  561. return {message: error, result: false};
  562. }
  563. return true;
  564. },
  565. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  566. var opt = $.extend({
  567. height: '100%',
  568. width: '100%'
  569. }, colOpt.editor);
  570. $.fn.power.defaults.xtype.yvsearch(htmlElement, opt);
  571. var $editor = htmlElement.down('yvsearch');
  572. $editor.css({
  573. border: 0,
  574. 'padding-left': '4px'
  575. });
  576. $editor.attr('yv-newline-field', 'searchbox');
  577. $editor.attr('yv-newline-type', 'searchbox');
  578. return $editor;
  579. },
  580. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  581. return editor.yvsearch('getValue');
  582. },
  583. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  584. editor.yvsearch('setValue', value || '');
  585. }
  586. });
  587. break;
  588. }
  589. case 'datebox': {
  590. $.extend(targetOpt, {
  591. editable: true,
  592. columntype: 'textbox',
  593. validation: validation,
  594. createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
  595. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  596. // 自从第一次被初始化后,防止第二次再进行初始化
  597. if ($.data(editor[0], 'inited')) {
  598. return;
  599. }
  600. $.data(editor[0], 'inited', true);
  601. var $dom = $(this.owner.element);
  602. editor.yvdate($.extend({
  603. height: '100%',
  604. width: '100%',
  605. onChange: function () {
  606. $dom.yvgrid('editChanged');
  607. if ($.type(colOpt.onChange) === 'function') {
  608. colOpt.onChange.apply(this, arguments);
  609. }
  610. }
  611. }, colOpt.editor));
  612. editor.on('focus', function () {
  613. $dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  614. });
  615. editor.attr('yv-inline-field', colOpt.field);
  616. editor.attr('yv-inline-xtype', 'datebox');
  617. editor.attr('yv-inline-row', row);
  618. },
  619. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  620. editor.yvdate('setValue', cellvalue);
  621. },
  622. geteditorvalue: function (row, cellvalue, editor) {
  623. return editor.yvdate('getValue');
  624. },
  625. validateeverpresentrowwidgetvalue: function (datafield, value, row, isPresentRow) {
  626. var error = (function () {
  627. if (colOpt.editor.required) {
  628. if ($.trim(value) === '') {
  629. return "必填";
  630. }
  631. }
  632. if (value) {
  633. if (!/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/.test(value) ||
  634. isNaN(moment(value).unix())) {
  635. return "必须填写合理的日期值,比如" + moment().format('YYYY-MM-DD');
  636. }
  637. }
  638. if ($.type(colOpt.editor.max) === 'string') {
  639. if (value && moment(value).unix() > moment(colOpt.editor.max).unix()) {
  640. return "必须小于 " + colOpt.editor.max;
  641. }
  642. }
  643. if ($.type(colOpt.editor.min) === 'string') {
  644. if (value && moment(value).unix() < moment(colOpt.editor.min).unix()) {
  645. return "必须大于 " + colOpt.editor.min;
  646. }
  647. }
  648. if ($.type(colOpt.editor.validate) === 'function') {
  649. return colOpt.editor.validate(value, row);
  650. }
  651. })();
  652. if (error) {
  653. return {message: error, result: false};
  654. }
  655. return true;
  656. },
  657. initEverPresentRowWidget: function (datafield, htmlElement) {
  658. },
  659. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  660. $.fn.power.defaults.xtype.yvdate(htmlElement,
  661. $.extend({
  662. height: '100%',
  663. width: '100%',
  664. onChange: colOpt.onChange
  665. }, colOpt.editor));
  666. var editor = htmlElement.down('yvdate');
  667. editor.css({
  668. border: 0,
  669. 'padding-left': '4px'
  670. });
  671. editor.attr('yv-newline-type', 'datebox');
  672. return editor;
  673. },
  674. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  675. return editor.yvdate('getValue');
  676. },
  677. setEverPresentRowWidgetValue: function (datafield, editor, value) {
  678. editor.yvdate('setValue', value);
  679. },
  680. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  681. editor.yvdate('setValue', value || '');
  682. }
  683. });
  684. break;
  685. }
  686. case 'numberbox': {
  687. $.extend(targetOpt, {
  688. editable: true,
  689. columntype: 'textbox',
  690. validation: validation,
  691. createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
  692. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  693. // 自从第一次被初始化后,防止第二次再进行初始化
  694. if ($.data(editor[0], 'inited')) {
  695. return;
  696. }
  697. $.data(editor[0], 'inited', true);
  698. var $dom = $(this.owner.element);
  699. editor.yvnumber(
  700. $.extend({}, colOpt.editor, {
  701. height: '100%',
  702. width: '100%',
  703. onChange: function (value, event) {
  704. $dom.yvgrid('editChanged');
  705. if ($.type(colOpt.editor.onChange) === 'function') {
  706. colOpt.editor.onChange.call(this, value, event);
  707. }
  708. }
  709. }));
  710. editor.on('focus', function () {
  711. //this.setSelectionRange(0, this.value.length);
  712. this.select();
  713. $dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  714. });
  715. editor.attr('yv-inline-field', colOpt.field);
  716. editor.attr('yv-inline-xtype', 'numberbox');
  717. editor.attr('yv-inline-row', row);
  718. },
  719. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  720. editor.yvnumber('setValue', cellvalue);
  721. },
  722. geteditorvalue: function (row, cellvalue, editor) {
  723. return editor.yvnumber('getValue');
  724. },
  725. validateeverpresentrowwidgetvalue: function (datafield, value, row, isPresentRow) {
  726. var error = (function () {
  727. if (colOpt.editor.required) {
  728. if ($.trim(value) === '') {
  729. return "必填";
  730. }
  731. }
  732. if ($.type(colOpt.editor.max) === 'number') {
  733. if (value && value > colOpt.editor.max) {
  734. return "必须小于" + colOpt.editor.max;
  735. }
  736. }
  737. if ($.type(colOpt.editor.min) === 'number') {
  738. if (value && value < colOpt.editor.min) {
  739. return "必须大于" + colOpt.editor.min;
  740. }
  741. }
  742. if ($.type(colOpt.editor.validate) === 'function') {
  743. return colOpt.editor.validate(value, row);
  744. }
  745. })();
  746. if (error) {
  747. return {message: error, result: false};
  748. }
  749. return true;
  750. },
  751. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  752. var opt = $.extend({
  753. height: '100%',
  754. width: '100%',
  755. }, colOpt.editor);
  756. $.fn.power.defaults.xtype.yvnumber(htmlElement, opt);
  757. var $editor = htmlElement.down('yvnumber');
  758. $editor.addClass('jqx-grid-cell-add-new-row')
  759. .attr('yv-newline-type', 'numberbox')
  760. .attr('yv-newline-field', colOpt.field);
  761. return $editor;
  762. },
  763. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  764. return editor.yvnumber('getValue');
  765. },
  766. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  767. editor.yvnumber('setValue', value || '');
  768. }
  769. });
  770. break;
  771. }
  772. case 'checkbox': {
  773. $.extend(targetOpt, {
  774. editable: true,
  775. validation: validation,
  776. columntype: 'custom',
  777. createeditor: function (row, cellvalue, htmlElement, celltext, cellwidth, cellheight) {
  778. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  779. // 自从第一次被初始化后,防止第二次再进行初始化
  780. if ($.data(htmlElement[0], 'inited')) {
  781. return;
  782. }
  783. $.data(htmlElement[0], 'inited', true);
  784. var $dom = $(this.owner.element);
  785. var opt = $.extend({}, colOpt.editor, {
  786. height: '100%',
  787. width: '100%',
  788. onChange: function (value) {
  789. $dom.yvgrid('editChanged');
  790. if ($.type(colOpt.editor.onChange) === 'function') {
  791. colOpt.editor.onChange.call(this, value);
  792. }
  793. }
  794. });
  795. $.fn.power.defaults.xtype.yvcheck(htmlElement, opt);
  796. var editor = htmlElement.down('yvcheck');
  797. editor.on('focus', function () {
  798. $dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  799. });
  800. editor.attr('yv-inline-field', colOpt.field);
  801. editor.attr('yv-inline-xtype', 'checkbox');
  802. editor.attr('yv-inline-row', row);
  803. },
  804. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  805. return editor.down('yvcheck').yvcheck('setValue', cellvalue);
  806. },
  807. geteditorvalue: function (row, cellvalue, editor) {
  808. return editor.down('yvcheck').yvcheck('getValue');
  809. },
  810. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  811. var opt = $.extend({
  812. height: '100%',
  813. width: '100%',
  814. }, colOpt.editor);
  815. $.fn.power.defaults.xtype.yvcheck(htmlElement, opt);
  816. var $editor = htmlElement.down('yvcheck');
  817. $editor.addClass('jqx-grid-cell-add-new-row')
  818. .attr('yv-newline-field', colOpt.field)
  819. .attr('yv-newline-type', 'checkbox');
  820. return $editor;
  821. },
  822. validateeverpresentrowwidgetvalue: function (datafield, value, row) {
  823. var error = (function () {
  824. if ($.type(colOpt.editor.validate) === 'function') {
  825. return colOpt.editor.validate(value, row);
  826. }
  827. })();
  828. if (error) {
  829. return {message: error, result: false};
  830. }
  831. return true;
  832. },
  833. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  834. return editor.yvcheck('getValue');
  835. },
  836. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  837. editor.yvcheck('setValue', value || '');
  838. }
  839. });
  840. break;
  841. }
  842. case 'combobox': {
  843. $.extend(targetOpt, {
  844. editable: true,
  845. columntype: 'combobox',
  846. validation: validation,
  847. createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
  848. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  849. // 自从第一次被初始化后,防止第二次再进行初始化
  850. if ($.data(editor[0], 'inited')) {
  851. return;
  852. }
  853. $.data(editor[0], 'inited', true);
  854. var $dom = $(this.owner.element);
  855. editor.jqxComboBox({
  856. //dropDownWidth: 250,
  857. animationType: 'none',
  858. //width: '100%',
  859. //height: cellheight + 2,
  860. //autoDropDownHeight: true,
  861. displayMember: colOpt.editor.textField,
  862. valueMember: colOpt.editor.valueField,
  863. source: colOpt.editor.data
  864. });
  865. editor.attr('yv-inline-field', colOpt.field);
  866. editor.attr('yv-inline-xtype', 'combobox');
  867. editor.attr('yv-inline-row', row);
  868. editor.find('.jqx-combobox-input').bind('focus', function () {
  869. //$dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  870. editor.jqxComboBox('open');
  871. }).bind('blur', function () {
  872. editor.jqxComboBox('close');
  873. });
  874. editor.on('change', function (event) {
  875. //只有键盘和鼠标的选择动作才允许,其他情况都不事件通知
  876. if (event.args.type !== 'keyboard' && event.args.type !== 'mouse') {
  877. return;
  878. }
  879. $dom.yvgrid('editChanged');
  880. if ($.type(colOpt.editor.onSelect) === 'function') {
  881. colOpt.editor.onSelect.call(this, $(editor).val());
  882. }
  883. });
  884. },
  885. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  886. editor.jqxComboBox('val', cellvalue);
  887. editor.width(editor.width() + 2);
  888. },
  889. geteditorvalue: function (row, cellvalue, editor) {
  890. return editor.jqxComboBox('val');
  891. },
  892. cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
  893. for (var i = 0; i < colOpt.editor.data.length; i++) {
  894. if (colOpt.editor.data[i][colOpt.editor.valueField] === $.trim(value)) {
  895. value = colOpt.editor.data[i][colOpt.editor.textField];
  896. break;
  897. }
  898. }
  899. if (!columnproperties) {
  900. columnproperties = {cellsalign: 'left'};
  901. }
  902. return '<div class="jqx-grid-cell-' + columnproperties.cellsalign + '-align" style="margin-top: 8.5px;">' + value + '</div>';
  903. },
  904. validateeverpresentrowwidgetvalue: function (datafield, value, row, isPresentRow) {
  905. var error = (function () {
  906. if (colOpt.editor.required) {
  907. if ($.trim(value) === '') {
  908. return "必填";
  909. }
  910. }
  911. if ($.type(colOpt.editor.validate) === 'function') {
  912. return colOpt.editor.validate(value, row);
  913. }
  914. })();
  915. if (error) {
  916. return {message: error, result: false};
  917. }
  918. return true;
  919. },
  920. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  921. var editor = $("<div />").appendTo(htmlElement);
  922. editor.jqxComboBox({
  923. width: '100%',
  924. height: '100%',
  925. dropDownWidth: 250,
  926. animationType: 'none',
  927. autoDropDownHeight: true,
  928. displayMember: colOpt.editor.textField,
  929. valueMember: colOpt.editor.valueField,
  930. source: colOpt.editor.data
  931. }).css({
  932. border: 0
  933. }).addClass('jqx-grid-cell-add-new-row');
  934. editor.attr('yv-newline-field', colOpt.field);
  935. editor.attr('yv-newline-type', 'combobox');
  936. editor.find('.jqx-combobox-input').bind('focus', function () {
  937. editor.jqxComboBox('open');
  938. }).bind('blur', function () {
  939. editor.jqxComboBox('close');
  940. });
  941. editor.on('change', function (event) {
  942. if ($.type(colOpt.editor.onSelect) === 'function') {
  943. colOpt.editor.onSelect.call(this, $(editor).val());
  944. }
  945. });
  946. return editor;
  947. },
  948. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  949. return editor.jqxComboBox('val');
  950. },
  951. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  952. editor.jqxComboBox('val', value || '');
  953. }
  954. });
  955. break;
  956. }
  957. default: {
  958. //textbox
  959. $.extend(targetOpt, {
  960. editable: true,
  961. columntype: 'textbox',
  962. validation: validation,
  963. createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
  964. // createeditor 在每行进行编辑时会调用一次,但是 editor 不会被更改,
  965. // 自从第一次被初始化后,防止第二次再进行初始化
  966. if ($.data(editor[0], 'inited')) {
  967. return;
  968. }
  969. $.data(editor[0], 'inited', true);
  970. var $dom = $(this.owner.element);
  971. editor.jqxInput({
  972. //width: '100%',
  973. height: '100%'
  974. });
  975. editor.attr('yv-inline-field', colOpt.field);
  976. editor.attr('yv-inline-xtype', 'textbox');
  977. editor.attr('yv-inline-row', row);
  978. editor.on('focus', function () {
  979. $dom.jqxGrid('ensurecellvisible', row, colOpt.field);
  980. });
  981. editor.on("input propertychange", function (event) {
  982. $dom.yvgrid('editChanged');
  983. if ($.type(colOpt.editor.onChange) === 'function') {
  984. colOpt.editor.onChange.call(this, editor.val(), event);
  985. }
  986. });
  987. },
  988. initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
  989. editor.jqxInput('val', cellvalue);
  990. },
  991. geteditorvalue: function (row, cellvalue, editor) {
  992. return editor.jqxInput('val');
  993. },
  994. validateeverpresentrowwidgetvalue: function (datafield, value, row, isPresentRow) {
  995. var error = (function () {
  996. if (colOpt.editor.required) {
  997. if ($.trim(value) === '') {
  998. return "必填";
  999. }
  1000. }
  1001. if ($.type(colOpt.editor.maxlength) === 'number') {
  1002. if (value && value.length > colOpt.editor.maxlength) {
  1003. return "必须小于" + colOpt.editor.maxlength + "个字符";
  1004. }
  1005. }
  1006. if ($.type(colOpt.editor.minlength) === 'number') {
  1007. if (value && value.length < colOpt.editor.minlength) {
  1008. return "必须大于" + colOpt.editor.minlength + "个字符";
  1009. }
  1010. }
  1011. if ($.type(colOpt.editor.validate) === 'function') {
  1012. return colOpt.editor.validate(value, row);
  1013. }
  1014. })();
  1015. if (error) {
  1016. return {message: error, result: false};
  1017. }
  1018. return true;
  1019. },
  1020. createEverPresentRowWidget: function (datafield, htmlElement, popup, addCallback) {
  1021. var editor = $("<input />").appendTo(htmlElement);
  1022. editor.jqxInput({
  1023. width: '100%',
  1024. height: '100%'
  1025. }).css({
  1026. 'padding-left': '4px',
  1027. border: 0
  1028. }).addClass('jqx-grid-cell-add-new-row');
  1029. editor.attr('yv-newline-field', datafield);
  1030. editor.attr('yv-newline-xtype', 'textbox');
  1031. editor.on("input propertychange", function (event) {
  1032. if ($.type(colOpt.editor.onChange) === 'function') {
  1033. colOpt.editor.onChange.call(this, editor.val(), event);
  1034. }
  1035. });
  1036. return editor;
  1037. },
  1038. getEverPresentRowWidgetValue: function (datafield, editor, validate) {
  1039. return editor.jqxInput('val');
  1040. },
  1041. resetEverPresentRowWidgetValue: function (datafield, editor, value) {
  1042. editor.jqxInput('val', value || '');
  1043. }
  1044. });
  1045. }//case default
  1046. }//switch
  1047. },
  1048. sourceOption: function ($dom, easyuiOpt, sourceOpt) {
  1049. if (!easyuiOpt.editable) {
  1050. return;
  1051. }
  1052. $.extend(sourceOpt, {
  1053. updaterow: function (rowid, rowdata, commit) {
  1054. if (this.isTemporary) {
  1055. //临时 setEditRow 操作造成的提交,可以忽略
  1056. commit(true);
  1057. return;
  1058. }
  1059. console.log('updaterow', rowdata);
  1060. if ($.type(easyuiOpt.onRowUpdate) === 'function') {
  1061. //有自定义的 onRowUpdate 方法
  1062. easyuiOpt.onRowUpdate.call(this, rowid, rowdata, commit);
  1063. } else {
  1064. //没有自定义,默认提交
  1065. commit(true);
  1066. }
  1067. },
  1068. deleterow: function (rowid, commit) {
  1069. console.log('deleterow', arguments);
  1070. if ($.type(easyuiOpt.onRowDelete) === 'function') {
  1071. //有自定义的 onRowDelete 方法
  1072. easyuiOpt.onRowDelete.call(this, rowid, commit);
  1073. } else {
  1074. //没有自定义,默认提交
  1075. commit(true);
  1076. }
  1077. },
  1078. addrow: function (rowid, rowdata, position, commit) {
  1079. var state = $.data($dom[0], 'yvgrid');
  1080. $.extend(rowdata, state.newRowData, rowdata);
  1081. console.log('addrow', rowdata);
  1082. if ($.type(easyuiOpt.onRowAppend) === 'function') {
  1083. //有自定义的 onRowAppend 方法
  1084. easyuiOpt.onRowAppend.call(this, rowid, rowdata, function (isCommit) {
  1085. commit(isCommit);
  1086. if (isCommit) {
  1087. //如果提交成功,需要删除 state.newRowData 方法
  1088. delete state.newRowData;
  1089. }
  1090. });
  1091. } else {
  1092. //没有自定义,默认提交
  1093. commit(true);
  1094. }
  1095. }
  1096. });
  1097. },
  1098. /**
  1099. * 表格设置
  1100. */
  1101. gridOption: function ($dom, easyuiOpt, jqxOpt) {
  1102. if (!easyuiOpt.editable) {
  1103. jqxOpt.editable = false;
  1104. return;
  1105. }
  1106. $.extend(jqxOpt, {
  1107. //selectionmode: 'singlerow',
  1108. //selectionmode: 'multiplerowsextended',
  1109. editmode: 'selectedrow', //如果换成 programmatic 可能造成无法多个单元格同时编辑
  1110. //editmode: 'programmatic',
  1111. editable: true,
  1112. showeverpresentrow: true,
  1113. everpresentrowposition: 'top',
  1114. });
  1115. if(easyuiOpt.allowAddNew === false){
  1116. $.extend(jqxOpt, {
  1117. showeverpresentrow: false
  1118. })
  1119. }
  1120. //双击后进入编辑
  1121. $dom.on('rowdoubleclick', function (event) {
  1122. $dom.yvgrid('beginEdit');
  1123. });
  1124. },
  1125. /**
  1126. * 按键
  1127. */
  1128. handlekeyboardnavigation: function (event) {
  1129. if (!this.editable) {
  1130. //以下按键都是为编辑而准备的,如果不允许编辑 就不需要过下面这些逻辑
  1131. return;
  1132. }
  1133. var $sender = $(event.target);
  1134. var $dom = $(this.element);
  1135. switch (event.keyCode) {
  1136. case 113: { //F2 进入编辑
  1137. if ($sender.closest('.jqx-grid-cell-add-new-row').length > 0) {
  1138. //添加行上按 F2 忽略
  1139. return true;
  1140. }
  1141. $dom.yvgrid('beginEdit', event);
  1142. return true;
  1143. }
  1144. case 27: { //esc
  1145. //添加行上按 ESC 代表重置
  1146. if ($sender.closest('.jqx-grid-cell-add-new-row').length > 0) {
  1147. $dom.yvgrid('addNewResetAction', event);
  1148. return true;
  1149. }
  1150. //命中在编辑格上,代表取消编辑
  1151. if (this.editcell != null) {
  1152. $dom.yvgrid('cancelEdit', event);
  1153. return true;
  1154. }
  1155. break;
  1156. }
  1157. case 13: {
  1158. //enter
  1159. if ($sender.attr('xtype') === 'yvsearch') {
  1160. //命中在 yvsearch 里,忽略该请求
  1161. return true;
  1162. }
  1163. if ($sender.closest('.jqx-grid-cell-add-new-row').length > 0) {
  1164. //命中在添加行上, 代表新建行
  1165. $dom.yvgrid('addNewAction', event);
  1166. return true;
  1167. }
  1168. if (this.hasOwnProperty('editcell')) {
  1169. //正在编辑模式中,提交本行的请求
  1170. $dom.yvgrid('endEdit', event);
  1171. return true;
  1172. }
  1173. break;
  1174. }
  1175. case 46: { //delete
  1176. if (event.target.tagName === 'INPUT') {
  1177. //输入框里面按下的 delete 键忽略
  1178. return;
  1179. }
  1180. if (this.editcell == null && $sender.closest('.jqx-grid-cell-add-new-row').length === 0) {
  1181. //没有编辑、没有新建,代表当前行的删除
  1182. $dom.yvgrid('deleteSelectedRow');
  1183. return true;
  1184. }
  1185. break;
  1186. }
  1187. }//switch
  1188. }//handlekeyboardnavigation
  1189. };//edit;
  1190. })(jQuery);