I'm displaying my results on an interactive grid. I'd like to be able to select multiple rows and click an edit button that will open up an “edit” form. I am having a number of problems:
Retrieve the car IDs of the rows selected. (I am having trouble accessing column values, I can access item values)
Pass a collection or array of ids to the edit form.
Save the collection.
Added more code in answer box by accident...……..
I made some progress but I am a little stuck. I followed the oracle blog and it was vey helpful. So on the attribute of the region I added the following code:
function (config) {
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3");
toolbarGroup.controls.push(
{
type: "BUTTON",
action: "updateCar",
label: "Edit Selected Cars",
hot: true,
});
config.toolbarData = toolbarData;
config.initActions = function (actions)
{
// Defining the action for activate button
actions.add(
{
name: "updateCar",
label: "Edit Selected Cars",
action: updateCar
});
}
function updateCar(event, focusElement)
{
var i, records, model, record,
view = apex.region("ig_car").widget().interactiveGrid("getCurrentView");
var vid = "";
model = view.model;
records = view.getSelectedRecords();
if (records.length > 0)
{
for (i = 0; i < records.length; i++)
{
record = records[i];
//alert("Under Development " + record[1]);
vid = vid + record[1] + "||";
apex.item("P18_CAR").setValue(vid);// This is not needed just to test
//the output
// call next page
// pass array as sql source or directly on page
}
}
}
return config;
}
This works. A button is displayed and when selected it gets the values from the interactive grid. The part I am stuck is how to call the next page and pass the multiple values (2 columns) to the page to be displayed and in a query to do an update.
Thank you if you can help me accomplish this!
Related
I am trying to fetch all the selected records from the interactive grid in Oracle APEX by writing the below piece of code. I have also declared #myStaticIgId as the static Id of my report.
var record, USER_NAME;
var x = '';
var l_role = $v("P2_ROLE");
var l_justification = $v("P2_JUSTIFICATION");
var l_date = $v("P2_DATE");
//Identify the particular interactive grid
var ig$ = apex.region("myStaticIgId").widget();
//Fetch the model for the interactive grid
var grid = ig$.interactiveGrid("getViews","grid");
//Fetch the model for the interactive grid
var model = ig$.interactiveGrid("getViews","grid").model;
//Fetch selected records
var selectedRecords = apex.region("myStaticIgId").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
alert(selectedRecords.length);
//Loop through selected records
for (idx=0; idx < selectedRecords.length; idx++) {
//Get the record
record = model.getRecord(selectedRecords[idx][0]);
alert(record);
//Get the current value for USER_NAME
USER_NAME = model.getValue(record,"USER_NAME");
// USER_NAME = 'Abha';
alert('submit 2');
}
The alert statement that I have written for returning the record value, returns NULL to me.
Can you please suggest, what needs to be done so as to get the proper record value in record variable.
Regards,
Abha
Finally, I got it working. the issue was the ordering of the primary key column. The primary key column should be the first column in the list after "APEX$ROW_SELECTOR" and "APEX$ROW_ACTION".
My column "ASSIGNMENT_NUMBER" with the primary key was not the first column while column "USER_NAME" was the first column in the REgions. Hence it was working for USER_NAME and not for "ASSIGNMENT_NUMBER". After changing the order of this column as first column, It worked.
Hope this also helps somebody!
I tested your code (with some changes) here and works.
1 - Define the region ID of your Interactive Grid.
2 - Go to chrome -> open console (press F12) -> try this code:
var gridID = "orders";
var ig$ = apex.region(gridID).widget();
var grid = ig$.interactiveGrid("getViews","grid");
var model = ig$.interactiveGrid("getViews","grid").model;
var selectedRecords = grid.getSelectedRecords();
for (idx = 0; idx < selectedRecords.length; idx++) {
record = model.getRecord(selectedRecords[idx][0]);
console.log(record);
console.log(model.getValue(record,"USER_NAME"));
}
I tested this code in this page: https://apex.oracle.com/pls/apex/f?p=145797:8
I am also having similar issue. Flag is "Selected List"(Yes/No). I am trying to change Flag value from "No" to "Yes" for selected Rows, However value is not getting changed.
I am using below code.
function changeFlag(){
var isVerified;
var ig$ = apex.region("New").widget();
var grid = ig$.interactiveGrid("getViews","grid");
var model = ig$.interactiveGrid("getViews","grid").model;
var selectedRecords = apex.region("New").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
for (idx=0; idx < selectedRecords.length; idx++) {
record = model.getRecord(selectedRecords[idx][0]);
console.log(record);
isVerified = model.getValue(record,"FLAG");
console.log(isVerified);
if (isVerified === 'N') {
model.setValue(record,"FLAG", 'Y');
}
}
}
Sample application is available in this link
I am not understanding where i made issue.
Actual issue is Update the flag for bulk records using IG. I am trying to change the value to "Yes" and then will save the records. I am stuck because of this issue.
i had already done adding a click handler to each Segment of my doughnut chart with adding the following Code :
$("#myChart").click(
function(evt){
var activePoints = myNewChart.getSegmentsAtEvent(evt);
var chartelementid = activePoints[0].label;
alert(chartelementid);
//$('.details div').css("display", "none");
//$('#' + chartelementid).show();
}
);
This works fine, when finished it should display an additional Div with Details for this segment.
Unfortunality my labels are more then just Single Words, so i'm struggeling to create div ID's with the same name...
My Idea is to add to every Segment an additional Data like value,label, etc. so it could be an ID. but if i just add the ID information to the Segment it will not exist as variable.
Add DataType:
var dataImprove = [
{
value: 30,
color:"#001155",
highlight: "#1c2f7c",
label: "KnowHow Erhalt / Transfer & Aufbau",
id:"test"
}
]
where can i add in chart.js an additional dataType like shown above my ID to be accessible in the DOM?
kind regards Marco
As an alternative pass a JSON string as your label, then intercept to render. For example:
var canvas = document.getElementById(id);
var d = canvas.getContext("2d");
var chart = new Chart(d).Pie(json, {
segmentStrokeWidth: 1,
tooltipTemplate: "<%=label%>", //default the label
customTooltips: function (tooltip) {
// Hide if no tooltip
if (!tooltip) {
return;
}
var tooltipObj = JSON.parse(tooltip.text);
// etc
already found : between line 999 and 1023 in chart.js before drawing - i've added the line
id: ChartElements[0].id,
so the Data with the name ID is in the DOM avaiable.
I want to refresh a dojo grid in my web page. I tried .refresh which is given in dojotoolkit.org without success. is there any other convenient way to do refreshing? Thanks in advance.
Maybe this helps. This is the way i refresh my Grid:
if(!registry.byId("GraphGrid")){
var grid = new EnhancedGrid({
id: 'GraphGrid',
store: GraphicStore,
query: { ident: "*" },
structure: layout,
rowSelector: '20px',
plugins: {
indirectSelection: {
headerSelector:true,
width:"40px",
styles:"text-align: center;"
}}
},"GridGraphicInMap");
/*Call startup() to render the grid*/
grid.startup();
dojo.connect(grid, "onRowClick", grid, function(evt){
var idx = evt.rowIndex,
item = this.getItem(idx);
// get a value out of the item
var value = this.store.getValue(item, "geom");
highlightGeometry(value,true);
// do something with the value.
});
}
else {
registry.byId("GraphGrid").setStore(GraphicStore);
}
When i first call my function the grid is generated. Evrytime i call the function later only the store is refreshed.
Regards, Miriam
I get this error when I try to remove all the elements in the array, which is the model for the selection Box. From what I understand this happens because I have the first row selected and I remove all items, in order to replace them again. The how should I do this to work?
// is only created the first time
weeks: new qx.data.Array()
// every time I change the year I have to
weeks.deleteAll();
// for each week in the year add the week
weeks.push(qx.data.marshal.Json.createModel({
label: "week: " + weeksNum
,fromDay: week.startDay
,toDay: week.endDay
}));
// the view
var weeksSelectBox = new qx.ui.form.SelectBox();
var weeksController = new qx.data.controller.List(this.__headerData.weeks, weeksSelectBox, 'label');
content.add(weeksSelectBox);
weeksSelectBox.addListener("changeSelection", function(e) {
var selectedItem = e.getData()[0];
var model = null;
if(selectedItem){
model = selectedItem.getModel()
}
this.__component.onWeekSelected(model);
}.bind(this));
how I can delete a row from a javascript function from a button
for example
If you're using a DataView, use the following:
DataView.deleteItem(RowID);//RowID is the actual ID of the row and not the row number
Grid.invalidate();
Grid.render();
If you only know the row number, you can get theRowID using:
var item = DataView.getItem(RowNum);//RowNum is the number of the row
var RowID = item.id
Suppose you are using jQuery
var grid;
$(function () {
// init options, load data
...
var columns = [];
columns[0] = {
id: 'id',
name: '#',
field: 'id', // suppose you have an id column in your data model
formatter: function (r, c, id, def, datactx) {
return 'X'; }
}
// init other columns
...
grid = new Slick.Grid($('#gridDiv'), data, columns, options);
}
function RemoveClick(databaseId, gridRow) {
// remove from serverside using databaseId
...
// if removed from serverside, remove from grid using
grid.removeRow(gridRow);
}
This is how i do it (not using any data provider though):
//assume that "grid" is your SlickGrid object and "row" is the row to be removed
var data = grid.getData();
data.splice(row, 1);
grid.setData(data);
grid.render();
I use this in a live project and it runs well. Of course, if you want to remove multiple rows then a few tweaks should be made, or if you use a data provider then you'd maybe want to remove the row only from the data provider and then have SlickGrid just refresh the rows.
Hope it helps :)
function deleteRows() {
var selectedIndexes = grid.getSelectedRows().sort().reverse();
var result = confirm("Are you sure you want to delete " + grid.getSelectedRows().length + " row(s)?");
if (result) {
$.each(selectedIndexes, function (index, value) {
var item = dataView.getItem(value); //RowNum is the number of the row
if (item)
dataView.deleteItem(item.id); //RowID is the actual ID of the row and not the row number
});
grid.invalidate();
grid.render();
}
}
var rowsToDelete = grid.getSelectedRows().sort().reverse();
for (var i = 0; i < rowsToDelete.length; i++) {
data.splice(rowsToDelete[i], 1);
}
grid.invalidate();
grid.setSelectedRows([]);
yes of course, I use it this way
var selrow = grid.getSelectedRows ();
data.splice(selrow, 1);
grid.invalidateAllRows();
grid.render ();
Greetings
hi
i'm used this script for delete row of SlickGrid
function deletefila(numrow)
{
alert("delete row"+numrow);
data.splice(numrow,1);
grid.removeAllRows();
grid.render();
//grid.removeRow(5);
//grid.updateRowCount();
//and then invalidate and re-render the grid by calling grid.removeAllRows() followed by grid.render().
}