In our training sessions, we frequently get interesting questions about the Interactive Grid. Here's a small selection:
Requirements:
There is a grid on the Scott.emp table with the static ID EMP
There is a select list named P1_JOB
- In the grid for the EMP table, the job for all employees should be set to a single unified value, which is defined in an item outside of the grid.
var model = apex.region("EMP").widget().interactiveGrid("getViews", "grid").model;
model.forEach(function(r) {
model.setValue(r, "JOB", $v("P1_JOB" )); // Setzen des Jobs pro Zeile
})
2. Only the entries selected using the checkbox (column 1) in the grid should be updated.
var grid = apex.region("EMP").widget().interactiveGrid("getViews","grid");
var model = grid.model;
var selectedRecords = grid.getSelectedRecords();
//console.log("Records" +selectedRecords.length);
for (idx = 0; idx < selectedRecords.length; idx++) {
record = model.getRecord(selectedRecords[idx][0]);
model.setValue(record, "JOB", $v( "P1_JOB" ));
//console.log(idx+ " " + selectedRecords[idx][1] ); //Felder [1] EMPNO [2] ENAME, [3] JOB ...
}
3. ou want to handle writing back to the database yourself? No problem. Simply replace the process with:
IF :APEX$ROW_STATUS='C' THEN
INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno)
VALUES (:EMPNO,:ENAME,:JOB,:MGR,:HIREDATE,:SAL,:COMM,:DEPTNO);
ELSIF :APEX$ROW_STATUS='U' THEN
UPDATE emp SET
ename=:ENAME,job=:JOB, mgr=:MGR,hiredate=:HIREDATE ,sal=:SAL,comm=:COMM, deptno=:DEPTNO
WHERE empno=:EMPNO ;
ELSIF :APEX$ROW_STATUS='D' THEN
DELETE FROM emp
WHERE empno=:EMPNO;
END IF;
That was a small excerpt from the many questions we get in our APEX courses. Do you have questions too? Then join one of our courses… we look forward to seeing you!