How to freeze first column in Interactive grid in Oracle Apex - oracle-apex

I have an interactive grid with source as : select header_1,header_2,header_3 from data;
I want HEADER_1 ,i.e. first column to freeze and others to scroll on display.
Also i am aware this can be done by end user by freezing the column, but can this also be done from back end?
How can this be achieved?

After you freeze column on IG, just got to Action/Report/Save and save it for all users.
To ensure that end user can't unfreeze column, go to IG column which you Froze, go to attributes in JavaScript initialization code and paste this code:
function(config) {
config.defaultGridColumnOptions = {
noHeaderActivate: true
};
return config; }
That's it.

Related

How to sort in Oracle Apex 19.1 Interactive Grid

I'm using Oracle Apex 19.1 on a 18.c platform.
I have a page with two regions: 1) Interactive Grid and 2) Interactive Report
I use the Interactive Grid to display a list of Producer names. When the user selects one of the names, the Interactive Report refreshes and displays the events assigned to that Producer. I use a Dynamic Action to update the Interactive Report.
This all works fine, except for the list in the Interactive Grid. It seems to display names in order by the table's PRIM_KEY and I want to sort the Interactive Grid by last name. The Source Code for the IG doesn't accept an Order By clause.
Select ac.first_name || ' ' || ac.last_name PRODUCER
From aff_contact ac, aff_contact_role acr
Where ac.prim_key = acr.contact_fkey
And acr.role = 'Producer'
;
The problem is, the column names in the IG toolbar's Actions / Data / Sort never populate. I wondered if the dual column in the Select statement was the problem, so I tested it with a simpler query for the Source:
Select last_name
From aff_contact
;
That still didn't produce columns to select for the sort. I receive a screen like the one below:
The Column select field has nothing to pull down. That holds true for both the original and the simplified query.
How can I get the IG to sort based on the LAST_NAME field? Is there another way to achieve this goal?
Thanks for looking at this.
After further checking, it seems that a VARCHAR2 column with a width <= 99 is selectable as a Sort or Control Break. A VARCHAR2 column with a width >= 100 is NOT selectable for Sort or Control Break in an interactive grid.
To identify the fields in the report Source I used the syntax:
cast( first_name as varchar2(32)) "FIRST_NAME",
cast( last_name as varchar2(32)) "LAST_NAME"
to avoid the default column width.
To sort by column:
01. Click the Actions menu, select Data, then Sort. The Sort dialog appears.
02. In the Sort dialog: Select a column, the sort direction (Ascending or Descending), and the null sorting behavior (Default, Nulls Always Last, or Nulls Always First).
a. Column - Select a column.
b. Direction - Select Descending or Ascending.
c. Nulls - Select First or Last.
03. To add another sort rule, click the Add button (+).
04. Click Save.
05. Click Report
06. Click Save
The interactive grid reloads.
Note:To ensure column sorting active. To ensure that you are login developer mode, otherwise it is not show other user

How I can make Mandatory add at least one row in Interactive grid in apex oracle

I have two region one form and one interactive grid like a master detail(company and company contact person ) how i can make the interactive grid mandatory ,the user can't submit page ,he/she need add at least one row in interactive grid ,
I can do that or I need to change the interactive grid to collection and count the row in validation
This one is a little tricky because of the way processes and validations work with Interactive Grids (they are executed once per submitted row). To work around this, I'll use a page item and a validation that works with it.
The basic idea of this solution is based on the fact that a new row will not have a primary key value. Here are the steps to reproduce (my example was on page 14, update the following as needed).
Create an Interactive Grid (IG) region. The primary key column should be Query Only (which ensures it's null for new rows).
Create a Hidden page item named P14_NULL_FOUND. Set Type under Server-side Condition to Never so that it never renders on the page.
Create an After Submit (before Validations) process. This process will NOT be associated with the IG so it will only fire once. Set the PL/SQL Code attribute to:
:P14_NULL_FOUND := 'NO';
That will clear out the value of the page item prior to the next process.
Create another After Submit process that runs just after the previous one. Set Editable Region to the IG. Then set the PL/SQL Code to something like the following:
if :PK_COLUMN_IN_IG is null
then
:P14_NULL_FOUND := 'YES';
end if;
You'll need to replace ":PK_COLUMN_IN_IG" with the name of the primary key column in the IG, such as ":EMPNO". This process will be run once for each submitted row in the IG. If a null value is found for the primary key column, then that would mean the user added a new row and the value of P14_NULL_FOUND would be set to 'YES'.
Create a new validation. This validation will NOT be associated with the IG so it will only fire once. Set Type to PL/SQL Expression. Set PL/SQL Expression to:
:P14_NULL_FOUND != 'NO'
Then set Error Message to something relevant.
At this point, you should be able to run the page and verify that the processes and validation are working correctly.
There is an another solution;
Create a page item like PX_ROWCOUNT which will hold the data of the row count of your IG.
Assign a static ID to your IG region.
Write a JS function to count the rows of the grid then set it to the page item. Sample function;
function f_setRowCount(){
var grid = apex.region("staticIDOfYourIG").widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var rowCount = 0;
model.forEach(function (record) {
rowCount ++;
});
$s("PX_ROWCOUNT",rowCount);
}
To submit your page and run this function, change your submit button's behavior to Defined by Dynamic Action. Execute your function when user clicks to that button then submit your page via DA.
Add validation to Processing section of the page and check your page item there; PLSQL Expression => :PX_ROWCOUNT > 0
The solution by Hamit works nicely, except of the case of deletion of a row.
My suggestion is to amend the above code by adding inside the loop an if statement to check whether the row is editable or no.
So the code will be
var grid = apex.region("staticIDOfYourIG").widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var rowCount = 0;
model.forEach(function (record) {
if (model.allowEdit(record)) {
rowCount ++;
}
});
$s("PX_ROWCOUNT",rowCount);

APEX changing row colors in an IG

I am following an example I found on-line as since I found it on the internet I know it must be correct. I am trying to search for a specific value in an IG and when it is found the line/row is highlighted with red text, Below it the logic I followed and screen shots. Please let me know what I am missing. He is using an employee example and I using my car dealership example. Thank you !
"Here's another approach that works great:
For an IR with this query:
select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO,
OFFSITE
from EMP
Define for the column JOB the following Static ID: MANAGER_STATIC
Then create a DA After Refresh on Region where On True Execute the following javascript with Fire
on Page Load=ON:
this.affectedElements.find('td[headers="MANAGER_STATIC"]').each(function(i) {
var lThis = $(this);
if (lThis.text() == "MANAGER") {
lThis.parent().children().css({
"background-color": "#C0C0C0"
});
}
});
And every row that has the value of MANAGER will be highlighted and this will respect pagination.
That Example appears to be for an Interactive Report, but you appear to be using an Interactive Grid.
The easiest way to do this (without coding) is to run the report and use the Actions Button to define Highlighting. E.G.
Fill out form similar to this (Change column selection and value to your requirement):
Afterwards, using the Action Button again to Report->Save the report so it saves the report for All Users.

Button to change selected records

I have an interactive grid with a bunch of records, and I want to set up a button on the page that changes one column in all records currently selected.
Running APEX 18.2, the IG has a whole bunch of columns and I want to change just one of them, but on a whole bunch of rows, so I do need a button.
The IG has ROWID as PK because the actual PK is assembled from 4 different columns.
I have spent some time googling this issue and have found a couple people with solutions:
http://thejavaessentials.blogspot.com/2017/03/getting-selected-rows-in-oracle-apex.html
This is the first, and simplest solution. But it doesn't return any rowid or anything like that, it returns the value in the first column.
Then I also found
http://apex-de.blogspot.com/2018/09/update-several-rows-in-tabular-form-grid.html
and
https://ruepprich.wordpress.com/2017/03/23/bulk-updating-interactive-grid-records/
Which are pretty similair and seem to be the best for me, but I get a Javascript error in the console: http://prntscr.com/n5wvqj
And I dont really know much Javascript, so I dont know what went wrong or how to best fix it.
I set up a Dynamic action on button click that executes Javascript and I have the selected element being the region named CUR_STAT.
var record;
//Identify the particular interactive grid
var ig$ = apex.region("CUR_STAT").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("CUR_STAT").widget().interactiveGrid("getViews","grid").view$.grid("getSelectedRecords");
//Loop through selected records and update value of the AVT_OBR column
for (idx=0; idx < selectedRecords.length; idx++)
{
//Get the record
record = model.getRecord(selectedRecords[idx][0]);
// set Value for column AVT_OBR on "D"
model.setValue(record,"AVT_OBR", 'D');
}
The column named AVT_OBR is a select list with display values(DA, NE) and return values(D, N). But I tried having it be a text field and it didnt help.
I want to be able to select multiple columns and change the data in those entries.
If possible I would also like to be able to change data in such a way in a hidden column. Or if I could get all the ROWIDs for selected records and execute a PLSQL block with them.
Ended up with noone responding so I spent a lot of time and finally came up with a solution.
var g = apex.region('myIG').widget().interactiveGrid('getViews','grid');
var r = g.getSelectedRecords();
for(i = 0; i < r.length; i++) {
g.model.setValue(r[i], 'myColumn', 'Value');
}
For some reason none of the solutions I found had worked. But I learned from those solutions and made this simple piece of code that does what I need.
Also, I was wanting to set up so I could do this set value on a hidden column, I achieved this by just having the column visible and editable, but then when running the page I clicked on the column and hid it, and set the current view as the default report.
If anyone stumbles upon this question, I hope it helps.

Initialize record on cell enter of XamDataGrid

Assume we have a XamDataGrid with 10 columns.
Column 1 is a XamComboEditor bound to a collection in the model
This can't be changed, the data is coming from a server and the combo's collection is based on different selections within the model so it's very dynamic.
Columns 2 - 10 are just normal alpha numeric fields
The problem:
When you enter a alpha numeric and start typing the model is initialized and everything is fine. However, if you go to the very last row, the non-initialized empty one, and click on the combo editor before entering any data into any of the other fields, the combo editor is empty.
Now I am well aware of why this is happening, it's clear that this is due to the model not being initialized yet. I'm just not sure the best method to fix this.
I would hope there is a property on the XamDataGrid that adjusts when the record is initialized but I've searched the Infragistics documentation and examples and I can't find anything.
There are events for:
EditModeStarting
EditModeStarted
EditModeEnding
EditModeEnded
private void OnCellEditModeStarting(object sender, EditModeStartingEventArgs args)
{
if (args.Cell.Field.Name == "TotalQuantity")
{
DataRecord record = args.Cell.Record;
if (record == null)
return;
MyGridEntry item = record.DataItem as MyGridEntry;
// Do a thing
}
}
You can also respond to the InitializeRecord event. It can fire for multiple reasons, such as cell editing, so check the state of your row model when responding to it. All these events are on the parent grid, not any FieldLayouts or Fields.
<i:XamDataGrid x:Name="myGrid"
InitializeRecord ="OnInitializeRecord"
EditModeStarting ="OnEditModeStarting">