FoxInCloud
grid - wcScriptJSadd
Gravatar is a globally recognized avatar based on your email address. grid - wcScriptJSadd
  Vincent H.
  All
  Dec 27, 2020 @ 03:40am

Hi Thierry,

I'm trying to hide some columns from a grid.
For that, I added this code:

Grid.Refresh_()

LOCAL Mid
WITH THISFORM 
   Mid = THIS.wcID
   IF .NOT. EMPTY (m.Mid)
      .wcScriptJSadd(TEXTMERGE([jQuery("#<<m.Mid>> :contains(false):nth-child(5)").css("display","none");]))
      .wcScriptJSadd(TEXTMERGE([jQuery("#<<m.Mid>> :contains(false):nth-child(4)").css("display","none");]))
   ENDIF
ENDWITH

It has no effect. Not better if I include it in xxx.css

However, it works well in the Firefox console. And I found this in the script of DOMEvent:

jQuery("#detailform_scx-grid :contains(false):nth-child(5)").css("display","none"); /* Généré le 27/12/2020 12:38:39 en 0,32 sec. par FAS  ...

An idea ?

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Dec 29, 2020 @ 02:34am

Hi Vincent,

to hide column #2 in http://foxincloud.com/tutotest/bs/RowColChange.tuto, you can test this code in browser console:

var oGrid = jQuery("#rowcolchange_scx-mygrid").prop('oGrid');
oGrid.setColumnIndices([0,2]);
oGrid.setColumnCount(2);
oGrid.refresh();

Assuming your grid has 6 columns and you want to hide columns #4 and #5, this VFP code should work in your case:

IF .NOT. EMPTY (THIS.wcID)
   LOCAL cJS
   text to cJS TEXTMERGE NOSHOW flags 1 pretext 3
      (function(){
      var oGrid = jQuery("#<<THIS.wcID>>").prop('oGrid');
      oGrid.setColumnIndices([0,1,2,3,6]);
      oGrid.setColumnCount(5);
      oGrid.refresh();
      })();
   endtext
   thisForm.wcScriptJSadd(m.cJS)
ENDIF

Be aware that:

  • setColumnIndices expects a JS array of indices of visible columns
  • column indices are 0-based
  • column indices are equal to VFP's .columnOrder-1; you may need to use this.columns(ii).columnOrder
  • hidden column still exist, you can later set them back to visible
Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Dec 29, 2020 @ 03:14am

Thanks Thierry for these very useful reminders

In my table, I want to remove the checkboxes concerning the titles (witch have []):

In my Grid.Init():

WITH THIS
   .Column2.DynamicCurrentControl = [IIF (.NOT. "[" $ CDetailForm.Libelle, "Vhcchk1", "Text1")]
   .Column3.DynamicCurrentControl = [IIF (.NOT. "[" $ CDetailForm.Libelle, "Vhcchk1", "Text1")]
ENDWITH
DODEFAULT()

And after this, the code I posted, which works in Firefox console mode but not so launched from the screen

Thanks in advance for your help

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Dec 29, 2020 @ 03:34am

Vincent,

Again an incomplete initial issue description… that's annoying…
Please ALWAYS DESCRIBE IN DETAILS: (1) what you get (2) what you expect, preferably each with a screenshot.
There are plenty of articles on how to properly describe an issue on a support forum, please take time to review some

Try setting at design time or in .Init(): .text1.controlSource = ''

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Dec 29, 2020 @ 04:25am

Well received ...

I had tried, but the empty value is not supported

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Dec 29, 2020 @ 04:29am

try setting .controlSource to a grid or form property set to " "

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Dec 29, 2020 @ 06:05am

Same punition ...

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  Vincent H.
  Dec 29, 2020 @ 06:07am

Is there a reason why my wScriptJSadd command is not being executed ?

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Dec 29, 2020 @ 07:41am

Try to clear column.controlSource and set it in both member controls (checkbox and textbox)

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Dec 31, 2020 @ 01:03am

It is not supported. So, I try to continue with JS.

First I run the command from the console:

As you can see, the last "false" is hidden.

I have inserted the wcScriptJSadd instructions into a [Command1] button.
The strangest thing is that by clicking, not only the "false" do not disappear but the deleted one reappears !
As if there was a refresh in the original state of the grid.

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Jan 2, 2021 @ 04:01am

awAJAX::cScriptJSadd_() makes sure your JS executes after grid update:

procedure grid.refresh_
…
local oAJAX as awAJAX of awServer.prg, cScriptJS
cScriptJS = textmerge([jQuery('#<<this.wcID>> span.aw-grid-cell:contains(false)').html('');])
=wlAJAX(@m.oAJAX) and m.oAJAX.cScriptJSadd_(m.cScriptJS)
Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Jan 2, 2021 @ 05:16am

Thanks Thierry,

Happy new year !

The image above displays the result at (1st) launch of the screen, then checking in the console of the syntax (OK) and reproduction (in the console) of the supposed error: wcID seems empty (which to me gene regularly)

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  Vincent H.
  Jan 2, 2021 @ 05:35am

Not the only problem.

I indicated the path of the screen in "hard" and the result is the same, the instruction is not hidden.

However, I do find it in the POST script:

<script_>
jQuery('#detailform_scx-grid span.aw-grid-cell:contains(false)').html('');
</script_>
Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  Vincent H.
  Jan 2, 2021 @ 06:16am

I saved your code (with the "hard" path) in CheckBox.interactiveChange()
When I click, this generates 2 POST requests. We can clearly see the "false" instructions disappear and then reappear. Here the detail of the 2 POST return:

XHRPOSThttp://localhost/snoTest/gridEditEvent.sno?&Event=click&ObjAddr=detailform_scx-grid-column2-vhcchk1&UserID=5XX162LNV&PageInit=&nReq=16&ValueType=boolean&Value=false
[HTTP/1.1 200 OK 640ms]

'detailform_scx-grid' grid script took 47 ms. to generate on the server, 16 ms to execute on the browser, total 63 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_() - state changes > JavaScript: 32 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_() - current state XML 31 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs_calias() - .RecordSource "CDetailForm" > RecordSet using Select-SQL: 15 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs_calias() - Current record located without a unique key found! To optimize response time, please create a candidate(unique) key: INDEX on <someUniqueExpr> TAG CDetailFor candidate or ALTER TABLE CDetailForm alter column <someField> unique and/or at design time or after assigning .RecordSource, set grid.wcPKexpr to the name of a field that you are sure has unique values across the record set: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs() - 'CDetailForm' RecordSet > XML (28 rows): 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_oxmlchanges_rows() - data changes: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_oxmlchanges() - state changes: 15 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_rs() - data changes > JS: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_events() - event handlers: 16 ms. FoxInCloud.js:142:43
XHRPOSThttp://localhost/snoTest/gridEditEvent.sno?&Event=click&ObjAddr=detailform_scx-grid-column2-vhcchk1&UserID=5XX162LNV&PageInit=&nReq=17&ValueType=boolean&Value=false
[HTTP/1.1 200 OK 517ms]

'detailform_scx-grid' grid script took 47 ms. to generate on the server, 16 ms to execute on the browser, total 63 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_() - state changes > JavaScript: 31 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_() - current state XML 15 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs_calias() - .RecordSource "CDetailForm" > RecordSet using Select-SQL: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs_calias() - Current record located without a unique key found! To optimize response time, please create a candidate(unique) key: INDEX on <someUniqueExpr> TAG CDetailFor candidate or ALTER TABLE CDetailForm alter column <someField> unique and/or at design time or after assigning .RecordSource, set grid.wcPKexpr to the name of a field that you are sure has unique values across the record set: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cxml_rs() - 'CDetailForm' RecordSet > XML (28 rows): 15 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_oxmlchanges_rows() - data changes: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_oxmlchanges() - state changes: 16 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_rs() - data changes > JS: 0 ms.
awhtml.fxp!Awhtmlgen.gethtml_grd_aw_cscript_events() - event handlers: 31 ms. FoxInCloud.js:142:43
Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Jan 2, 2021 @ 06:21am

Move the code to thisForm.wUserAction_Post()

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Jan 2, 2021 @ 06:46am

It's OK, but only when I click on my checkbox, not at the initial display.

For this, I initialize my grid with:

   .Column2.DynamicFontSize = [IIF (.NOT. "[" $ CDetailForm.Libelle, 9, 0)]

Not very elegant but effective

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Jan 2, 2021 @ 07:27am

Call thisform.wUserAction_post() in thisform.Init() or move the code back to grid.refresh_() and call grid.refresh() from thisform.wUserAction_post()

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Jan 2, 2021 @ 07:35am

It doesn't work, I tried in Activate()
It seems logical, the code intervenes too early.

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Jan 6, 2021 @ 01:19am

This should be enough:

procedure grid.wcHTMLgen
lparameters toHTMLgen, tlInnerHTML
toHTMLgen.cScriptJSadd_(Textmerge("jQuery('#<<this.wcID>>').prop('oGrid')['onControlRefreshed']=function(){jQuery(this.element()).find('span.aw-grid-cell:contains(false)').html('');}"))
Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  Vincent H.
  FoxInCloud Support - Thierry N.
  Jan 6, 2021 @ 01:41am

Waouh, impressive !
But it doesn't work. Here is what I find in the script of the POST command:

jQuery('#detailform_scx-grid').prop('oGrid')['onControlRefreshed']=function(){jQuery(this.element()).find('span.aw-grid-cell:contains(false)').html('');}

Don't worry, my "bidouille" with FontSize and your wUserAction_Post are working

Gravatar is a globally recognized avatar based on your email address. re: grid - wcScriptJSadd
  FoxInCloud Support - Thierry N.
  Vincent H.
  Jan 6, 2021 @ 02:29am

But it doesn't work

Again, this alone doesn’t work in a public forum.

People reading this thread, including me, need to know/understand why “it doesn't work”: you need to spend some time debugging, and reporting back here your observations.

  • any JavaScript error?
  • does it work in the console?
  • using alert() or debugger;, do you see the code execute, when?
  • screenshot of any change you see

Free support requires that both side to do their part of the work. It’s a give-give trade, not one-way.

© 1996-2021