Update Drag/Drop Grid(s) via javascript
Posted: Wed Jan 11, 2017 10:04 am
We are attempting to use JavaScript to update the grid 'ondrop' as opposed to returning to the server each time. We have accomplished this one time in the screen but on the second attempt, viewing the data within the grids still has the original data. The grids are using bound fields loaded from RPG. Extra subfile records are added to each grid to ensure there is enough space to drop from one grid to the other.
This is what the grids look like when the screen is loaded. During 'ondrop' we are moving data from one to the other with successful display. Although the grids are displaying correctly, when attempting to drag/drop again, the JavaScript is seeing the grid data as if it hadn't changed from the original. This code is in the 'ondrop' for both grids as we want to be able to move them back and forth.
This is what the grids look like when the screen is loaded. During 'ondrop' we are moving data from one to the other with successful display. Although the grids are displaying correctly, when attempting to drag/drop again, the JavaScript is seeing the grid data as if it hadn't changed from the original. This code is in the 'ondrop' for both grids as we want to be able to move them back and forth.
Code: Select all
var source = getObj(pui.dragDropInfo["dd element id"]);
var target = getObj(pui.dragDropInfo["target element id"]);
var sourceRRN = pui.dragDropInfo["dd record number"];
var targetRRN = pui.dragDropInfo["target record number"];
var sourceCnt = source.grid.getRecordCount();
var targetCnt = target.grid.getRecordCount();
var i1=0;
// Load source arrays
var sourceDesc = [];
var sourceItem = [];
for (i1=1; i1<=sourceCnt; i1++) {
sourceDesc[i1] = source.grid.getDataValue(i1, "scDesc");
sourceItem[i1] = source.grid.getDataValue(i1, "scItem");
}
// Load target arrays
var targetDesc = [];
var targetItem = [];
for (i1=1; i1<=targetCnt; i1++) {
targetDesc[i1] = target.grid.getDataValue(i1, "scDesc");
targetItem[i1] = target.grid.getDataValue(i1, "scItem");
}
// Add record to target arrays
targetRRN += 1;
targetDesc.splice(targetRRN, 0, sourceDesc[sourceRRN]);
targetItem.splice(targetRRN, 0, sourceItem[sourceRRN]);
// Remove record from source arrays
sourceDesc.splice(sourceRRN, 1);
sourceItem.splice(sourceRRN, 1);
// Update target grid
for (i1=1; i1<=targetCnt+1; i1++) {
target.grid.setDataValue(i1, "scDesc", targetDesc[i1]);
target.grid.setDataValue(i1, "scItem", targetItem[i1]);
}
// Update source grid
if (source !== target) {
for (i1=1; i1<=sourceCnt; i1++) {
if (sourceDesc[i1] === undefined) {
sourceDesc[i1] = "";
sourceItem[i1] = "";
}
source.grid.setDataValue(i1, "scDesc", sourceDesc[i1]);
source.grid.setDataValue(i1, "scItem", sourceItem[i1]);
}
}
source.grid.render();
source.grid.refresh();
target.grid.render();
target.grid.refresh();
pui.dragDropInfo.cancel = true;