注意:代碼僅在APEX18.1中測(cè)試過(guò)
案例說(shuō)明:通過(guò)監(jiān)聽(tīng)I(yíng)G IDNUM列改變,自動(dòng)填充BIRTH列值
運(yùn)行說(shuō)明:將代碼拷貝到IG所在頁(yè)面,放入頁(yè)面“加載時(shí)執(zhí)行”,修改IG靜態(tài)ID,以及其他信息,保存后運(yùn)行。
案例代碼:
(function(apex,debug){
var
? // IG插件靜態(tài)ID
? // IG static id
? igId='customerList',
? // IG插件實(shí)例
? // IG instance
? ig=apex.region(igId).widget(),
? // IG視圖層實(shí)例
? // IG view
? vw=ig.interactiveGrid('getViews'),
? // IG模型實(shí)例
? // IG model
? md=vw.grid.model,
? // IG模型變更事件回調(diào)
? // IG change notification callback
? mdChg=function(chgType,chg) {
? ? switch(chgType) {
? ? ? case 'set':
? ? ? ? // IDNUM列改變
? ? ? ? // if IDNUM column changed
? ? ? ? if(chg.field === 'IDNUM') {
? ? ? ? ? // BIRTH列已有值
? ? ? ? ? // if birth column value exists ignore
? ? ? ? ? if(md.getValue(chg.record,'BIRTH')) {
? ? ? ? ? ? return;
? ? ? ? ? }
? ? ? ? ? var
? ? ? ? ? ? // get editing row record or else chg.record
? ? ? ? ? ? rec = md.getRecord(chg.recordId),
? ? ? ? ? ? // 取新值
? ? ? ? ? ? // get idnum column new value
? ? ? ? ? ? // chg.oldval get old value
? ? ? ? ? ? pin = md.getValue(rec,'IDNUM'),
? ? ? ? ? ? // 設(shè)置BIRTH列的返回值,SET:設(shè)置成功,NC:數(shù)據(jù)無(wú)改變,DUP:recordId重復(fù)
? ? ? ? ? ? // Set birth column value and assign return value to ret variable
? ? ? ? ? ? // possible return values are: SET, NC, DUP
? ? ? ? ? ? // SET: set success
? ? ? ? ? ? // NC: set failed, value not change
? ? ? ? ? ? // DUP: set failed, record id duplicated
? ? ? ? ? ? ret = md.setValue(rec,'BIRTH',[pin.substring(6,10),pin.substring(10,12),pin.substring(12,14)].join('-'));
? ? ? ? ? // 設(shè)置成功
? ? ? ? ? // set BIRTH column value success
? ? ? ? ? if(ret === 'SET') {
? ? ? ? ? ? // 用setData刷新view行,不然view不會(huì)刷新:(
? ? ? ? ? ? // setData必須傳數(shù)組
? ? ? ? ? ? // call model setData method to refresh view row else view will not get refreshed.
? ? ? ? ? ? // setValue don't refresh view, why?
? ? ? ? ? ? md.setData([rec], md.indexOf(rec));
? ? ? ? ? }
? ? ? ? }
? ? ? ? break;
? ? ? default:
? ? ? ? // console.info('SET ' + chg.field);
? ? ? ? break;
? ? }
? };
? // 注冊(cè)變更事件回調(diào),詳見(jiàn)#IMAGE_PREFIX/libraries/apex/model.js
? // register change notifications callback, see:#IMAGE_PREFIX/libraries/apex/model.js
? md.subscribe({onChange:mdChg});
})(apex,apex.debug);