Hello,
I have been running into an issue implementing a solution in Oracle Apex 5.1.1 interactive grid. I am trying to reorder a row(s) position in an interactive grid using javascript without requerying or submitting to the database. Right now I have a solution that has a sequence column and I update the sequence number and then invoke the save action using javascript but I would like the users to have a visual of the new row sequence without requerying. Below is the code I use for moving selected rows down.
var gridView = apex.region("build_task_results").widget().interactiveGrid("getCurrentView");
var gridModel = gridView.model;
var allRecords = {};
var selectedRecords = gridView.getSelectedRecords();
var i, recordCount, highestRow, rowInd, row1, row2, rows = [], seq;
recordCount=1;
gridModel.forEach(function(r){allRecords[recordCount] = r; recordCount++;})
if (selectedRecords.length == 0)
{
apex.message.alert( "You must select at least one build task.", function(){});
return;
}
highestRow = null;
for (i = 0; i < selectedRecords.length; i++)
{
rows.push(parseInt(gridModel.getValue(selectedRecords[i],"TASK_SEQUENCE")));
rowInd = parseInt(gridModel.getValue(selectedRecords[i],"TASK_SEQUENCE"));
if (highestRow == null)
{
highestRow = rowInd;
}
else
{
if (rowInd > highestRow)
{
highestRow = rowInd;
}
}
}
if (highestRow == recordCount-1)
{
apex.message.alert("The bottom Build Task row cannot go any lower. Please select a higher row.", function(){});
return;
}
rows.sort(function(a,b){return b-a});
for (i = 0; i < rows.length; i++)
{
rowInd = rows[i];
row1 = allRecords[rowInd+1];
row2 = allRecords[rowInd];
allRecords[rowInd+1] = row2;
allRecords[rowInd] = row1;
}
$.each(allRecords,function(key,element)
{
gridModel.setValue(gridModel.getRecord(allRecords[key][0]),"TASK_SEQUENCE",""+key);
});
apex.submit();