Align a Table Column

In a table list I have a “text” record field containing a integer, decimal or a text value. I want it aligned left (text) or aligned right (integer, decimal) in the list depending on the value. The only way this works automatically is with a variant field column. This field is not a record field so I’m loosing the ability to filter on that field. Any hint’s?

Do you want your results to be shown in a form? If so, I just made a test which seems to give the results you want: 1- Make a text field containing the information in the table 2- On the form, instead of showing the field, show a variant variable containing the value, after evaluation. Your form will show the data aligned as you want, and the user will still have the ability to filter on the text value (if the field name is the same than the caption of your variant, he will see no difference).

duh, I just did the following: 1. Created a global var: vValue as Variant 2. Created a new Column Name: vColumn Source Expr: vValue 3. In the OnAfterGetrecord event added: EVALUATE(vValue, rec.field); Result: In the form the column shows “Uninitialized” with every record. 4. I then changed vValue to “Text” and it works but no filter. What did I do wrong?

Hi

quote:


[Ok :=] EVALUATE(Variable, String) Ok Data type: boolean A return code which reflects whether an error occurred during the evaluation of the string. If Ok is… It means… TRUE No errors occurred during the evaluation of the string. The system assigned the value to Variable. FALSE Errors occurred during the evaluation of the string. The system did not modify the original value of Variable. If you omit this optional return value and an error occurs during the evaluation of the string, a run-time error occurs. If you include it, the system assumes you will handle any errors. Variable Data type: boolean, integer, option, date, time, text constant, code or GUID. Any type of variable. The value of the string is assigned to the variable. String Data type: text constant or code A string containing a value of any simple C/AL data type.


According to the OnLine Help (above) you cannot Evaluate a Variable Type Variant. The best way to get the Text / Integer Alignments you want would be to create the Variable as a Type Code of nn Length.

Type Code aligns a decimal value to the left (because of comma or dot) What did David explain then…

Sorry, Maybe I have not been specific enough… Here is what I put in the OnAfterGetRecord() trigger: // Variables // Rec.MyText : the text contained in the record // MyVariant: Variant that will be shown on the form // MyDec: decimal // MyInt: integer IF EVALUATE(MyDec, Rec.MyText) THEN MyVariant := MyDec ELSE IF EVALUATE(MyInt, Rec.MyText) THEN MyVariant := MyInt ELSE MyVariant := Rec.MyText; Doing like this, all your text will be aligned to the left and decimal and integer will be aligned to the right. It will also be possible to filter or even sort (add a key) on Rec.MyText This solution will require extra coding if you want the user to be able to change the values in the “variant field”.

Thanks for your answer, This is what I did as explained in my first message. The problem is the user can’t Filter (F7) on the Column “MyVariant”.

Oops! Sorry, I was using CTRL-F7 to filter with a “table filter”. It works, but it’s not “user friendly”. Let’s see if there a possibility to override the Field Filter (F7) functionnality…

Oops me too! I still hope there’s a solution for F7 but I can live with CTRL-F7 you know. What I don’t like with the variant solution: 9999999.999 On screen: 9,999,999.999 9999999.99 On screen: 9,999,999.99 9999999 On Screen: 9,999,999 I want: 9999999.999 On screen: 9999999.999 9999999.99 On screen: 9999999.99 9999999 On Screen: 9999999 Anyone?

Oops again! CTRL-F7 is ok but with variant the find CTRL-F is gone too. So back to the first question?

Well… with all the side-effects to this variant solution, maybe we should start considering doing it the “Navision way” ! What about showing your “unformatted data” as is and maybe create three extra fields to show the decimal value, integer values and text value?

I wish it was possible :slight_smile: I need to show 12 columns with this condition. So 12 x 3 - 36 columns. The field chooser would show 36 fields… Another problem with this solution is that per record (row) de data changes: ------+--------+---------+ 9999| 999| 9999| XXXX | 99999|XXXX | XXXX |XXXX |XXXX | 999,99| 9,9|XXXXXXX | XXXX | 9999| 999| ------+--------+---------+ The variant solution above does all that …snif… but has those side-effects. I also tried aligning the text to the left and adding leading spaces: - only works with “courier new” font and then looks strange.

Hi all I just tried one thing this morning. Like many others, i put a field to put the formatted value in on the form (and used Courier New font to align the numeric codes on this textbox - not very pretty, but it works[:)]). I then made a decimal variable called evalnum and put the following code into the OnAfterGetRecord trigger: if evaluate(evalnum, code) then formatted := format(evalnum, code) else formatted := code;

Sorry - copied the wrong codepiece[:I] this is the working one: IF EVALUATE(evalnum, Code) THEN formatted := FORMAT(evalnum, 10) ELSE formatted := Code; I made a testform using the country table and made some countries up with numeric and “decimal” values for the Code field for this example

I’m thinking of using the onformat event to look at the length of the string (digits, commas, dots). Count the smaller, middle, larger digits (screen size) Subtract this total size from width and set the indention. I already tried it without looking at the “screen fontsize” and this works.

It now does work as described above and the only extra thing was saving the current width for the column. When a user resizes the column the onactivate event fires and i need to compare if the width has changed. CTRL-F7, F7, CTRL-F all work, Left and Right align works, Thank you all.