PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Row based Column locking / disabling  (Read 757 times)

Zereliq

  • Member
  • **
  • Posts: 16
    • View Profile
Row based Column locking / disabling
« on: August 23, 2022, 10:21:22 AM »
Fairly simple question:
Is it possible to make some rows locked and others open see images for example :D
And if it is possible, would this be possible with an [if] block based on the row number


Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3701
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Row based Column locking / disabling
« Reply #1 on: August 23, 2022, 10:56:01 AM »
There is actually a pretty easy way to do this.

On the memory file used to maintain the grid add a field and call it something like lockrow$.

Now on the grid definition for the cells you want locked add the option (lockrow$) so the column definition looks something like this:

[col Source=clientid$ ttl="Client" width=10 (lockrow$)][/col]

Now on the row you want locked simply set the variable lockrow$ to "locked".

Basically when Webster processes the column it will evaluate the expression (lockrow$) which will be "locked".  You can have any options represented as fields in the grid memory file or event have things such as class=(fieldname$)

Zereliq

  • Member
  • **
  • Posts: 16
    • View Profile
Re: Row based Column locking / disabling
« Reply #2 on: September 07, 2022, 08:17:02 AM »
After a lot of playing around and also letting some college's with a lot more PxPlus experience try to get it to work we still have not been able to lock rows/fields based on a variable. What it seems to do is eigther lock all or unlock none.

We were able to determine that if you make a button that switches the state of the variable it changes all fields/rows that have the variable included. so sadly still have not found the solution to this question, any suggestions?

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3701
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Row based Column locking / disabling
« Reply #3 on: September 07, 2022, 10:59:03 AM »
Sorry, my bad, I should have noted and mentioned that in the grid the [col] is evaluated once during the grid definition, but the values between [col] and [/col] are done on each row so my example was incorrect.

So here is HTML that shows how to accomplish what you are looking for:

Code: [Select]
[ttl]Grid Demo[/ttl]

[form program=grid_sep7]

[subttl]Grid below shows locking columns[/subttl]
[grid mygrid size=50% program=grid_sep7]
[col ttl="Col1" width=10][input col1$ (lck1$)][/col]
[col width=15 ttl$="Col2"][input col2$ class="text_blue,font_bold" (lck2$)][/col]
[col ttl="Col3" width=15 class="align_center"][input col3$ (lck3$)][/col]
[/grid][/form]

You will notice that the (lckx$) option is inside the [col] short code tags thus will be evaluated on each row.

Here is the associated program that loads the grid and the lock settings.

Code: [Select]
load_grid:
  enter gridhdl
 !
  open (hfn,iol=grid_iol)"*memory*"
  gridhdl=lfo
 !
  for rowno=1 to 15
  col1$="Col1/Row"+str(rowno)
  col2$="Col2/Row"+str(rowno)
  col3$="Col3/Row"+str(rowno)
 !
  if mod(rowno,2)=0 \
   then lck1$="locked" \
   else lck1$=""
  if mod(rowno,3)=0 \
   then lck2$="locked" \
   else lck2$=""
  if mod(rowno,4)=0 \
   then lck3$="locked" \
   else lck3$=""
 !
  write (gridhdl)
  next rowno
 !
  end
 !
 grid_iol: \
  iolist col1$,lck1$,col2$,lck2$,col3$,lck3$

Now because of the way a grid works, when you run this the locked cells will not show as grey background.  This is because locked cells in a grid cascade the cell background color.  If you want them to show as a grey background, you can get around this by adding a class of something like "dynalock" to the [grid] definition then in your system setup add the following custom CSS line:

div.dynalock input[readonly] { background-color: var(--clrbck-locked) !important; }






Zereliq

  • Member
  • **
  • Posts: 16
    • View Profile
Re: Row based Column locking / disabling
« Reply #4 on: September 12, 2022, 04:39:05 AM »
Hey Mike,

This seems to work nicely thanks a lot!

also added some extra css to make other items appear locked too:
Code: [Select]
div.dynalock ._td:has(input[readonly]), div.dynalock ._td:has(input[data-lock="Y"]) {
 background-color: var(--clrbck-locked) !important;
}

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3701
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Row based Column locking / disabling
« Reply #5 on: September 12, 2022, 08:51:25 AM »
Glad it worked for you.

One thing, the :has(...) CSS selector is not supported on all browsers -- specifically its not supported by Firefox without user enabling it.

https://caniuse.com/css-has

Long-term it will likely work, but you may find some issues depending on the browser being used.

Zereliq

  • Member
  • **
  • Posts: 16
    • View Profile
Re: Row based Column locking / disabling
« Reply #6 on: September 13, 2022, 09:42:58 AM »
seeing how recently Safari has implemented the :has() function i don't think it will take long for Firefox to do the same,
but since we're using the project mostly internally i dont think we'll run into that obstacle nevertheless i will definitly keep it in mind when using it in future webster+ projects  ;)

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3701
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Row based Column locking / disabling
« Reply #7 on: September 13, 2022, 10:01:19 AM »
Technically FireFox has implemented the has () function however you have to this is done based on the layout.css.has-selector.enabled flag which the user has to enable.

Zereliq

  • Member
  • **
  • Posts: 16
    • View Profile
Re: Row based Column locking / disabling
« Reply #8 on: September 14, 2022, 05:50:44 AM »
so i think i already know the awnser to this question but its worth asking;

is it possible to change/update a variable like the "locked" after the write?

so for example im trying to change background-colors of cells based on changed made in other cells
or changing locks also based on changes made in other cells.

project_bg$="red"
[class=(project_bg$)]



Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3701
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Row based Column locking / disabling
« Reply #9 on: September 16, 2022, 08:23:12 PM »
Sure -- Set a variable to either text_red (for red text) or fill_red (for red background) then add class=(color$) or whatever your variable is and set the variable to "text_red" or "fill_red".

You could also do something like:    class=("fill_"+backClr$)