2
votes

I have an interactive grid with a list of records and lets say it has a date column. Now i only want to show those records or make only those records editable whose month in that date column is equal to the current month on page load. Now i know that a dynamic action can be created with execute javascript code as the option. But what would be the actual code to do it? I tried to access the grid with this

var grid = apex.region("emp").widget().interactiveGrid("getViews", "grid");

Then i can use the grid.model._data to get the records and loop through it and check the date column values and verify if it is current month or not, but after checking i don't know as to set the css for that particular row as {display: none;}. Any help would be appreciated. Thanks.

2

2 Answers

2
votes

Try this:

1 - Create a dynamic action in your interactive grid on the column that you want disable

Event: Row Initialization [Interactive Grid]

Selection Type: Columns

Region: Your grid region

Columns: Your column to disable or enable

2 - On Client Side Condition:

Type: JavaScript expression

Javascript Expression:

//Suppose there is a function (getMonth) 
//that returns the number of the month (1..12) in a date string;
//you can do this expression.
getMonth($(this.triggeringElement).val()) != ((new Date()).getMonth() + 1)

3 - True action

Disable

Selection type: Columns

Columns : The column to want disable or enable

Example: https://apex.oracle.com/pls/apex/f?p=145797:8

The column "CREDIT LIMIT" is disable when the value is 3000

1
votes

i only want to show those records (...) whose month in that date column is equal to the current month on page load

As interactive grid's source is a SELECT statement, why wouldn't you include a WHERE clause which says something like this:

where trunc(date_column, 'mm') = trunc(sysdate, 'mm')

Yes, I know - possible performance impact (index on DATE_COLUMN not being used) and stuff, but that's just the general idea. Could be further improved if it turns out to be OK.

[EDIT, after seeing the comment]

No problem in changing the WHERE clause:

where date_column >= 
  case when to_number(to_char(sysdate, 'dd')) <= 5 then trunc(add_months(sysdate, -1), 'mm')
       else trunc(sysdate, 'mm')
  end