Aller au contenu principal
Version: 20 R5 BETA

Programmation avancée avec Javascript

A 4D View Pro Area is a Web Area form object that uses the embedded web rendering engine. As such, it behaves just like any other web area, and you can get it to execute Javascript code by calling the WA Evaluate Javascript 4D command.

Since 4D View Pro is powered by the SpreadJS spreadsheet solution, you can also call SpreadJS Javascript methods in 4D View Pro areas.

Exemple concret : masquer le ruban

4D View Pro étant une zone Web, vous pouvez sélectionner un élément de page Web et modifier son comportement à l'aide de Javascript. The following example hides the spreadJS Ribbon:

//Méthode objet du bouton

var $js; $answer : Text

$js:="document.getElementsByClassName('ribbon')[0].setAttribute('style','display: none');"

$js+="window.dispatchEvent(new Event('resize'));"

$answer:=WA Evaluate JavaScript(*; "ViewProArea"; $js)

Appeler des méthodes JavaScript de SpreadJS

Vous pouvez exploiter la bibliothèque de méthodes Javascript de SpreadJS et les appeler directement pour gérer vos feuilles de calcul.

4D has a built-in Utils.spread property that gives access to the spreadsheet document (also called workbook) inside the 4D View Pro area, making it simpler to call the SpreadJS Workbook methods.

Exemple

Le code suivant annule la dernière action dans la feuille de calcul :

WA Evaluate JavaScript(*; "ViewProArea"; "Utils.spread.undoManager().undo()")

Dépôt 4D View Pro Tips

4D-View-Pro-Tips is a GitHub repository that contains a project full of useful functions, allowing to manage floating pictures, sort columns or rows, create a custom culture, and much more! N'hésitez pas à le cloner et à l'expérimenter !