APEX interactive grid dynamic set column value example

注意:代碼僅在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);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容