Vaadin grid - gridpro ComboBox Editor - grid

Grid Pro features three recommended built-in editors: Text Field, Checkbox, and Select.
Ho can you manage a list with key and value properties?
For example:
Country list
I'm unable to show country name in the select value and save the id in the database record.
I usually rely on ComboBox when I manage a list with key and value.
Combobox is not present in the list of built-in editors.
Do you suggest to write your own editor?

Let's assume you have a Country class with the properties id and name. And a Person class with a country property. You display a GridPro<Person>.
You can make a Select editor and define it's itemLabelGenerator (or renderer, if you want to show a flag or something) to show Country::getName. **
The saving to the database should be handled by the annotations on the relation. Usually using JPA, there would be a #ManyToOne relation between Person and Country, and save the country-FK (id, specified using #Id) in the person table.
** I don't use Grid Pro, but upon inspection of the code I can see that by using gridPro.addEditColumn(Person::getCountry).select(Person::setCountry, countriesList) you cannot specify the itemLabelGenerator/renderer.
However, you could prepare your own Select component and use the EditColumnConfigurator::custommethod.
Select<Country> countryEditorComponent = new Select<>();
countryEditorComponent.setItems(countriesList);
countryEditorComponent.setItemLabelGenerator(country -> country.getName());
gridPro.addEditColumn(Person::getCountry).custom(countryEditorComponent , Person::setCountry).setHeader("Country");

Related

Filter and Bind a Multiselect

I am trying to implement a Many-to-Many relation between a class and its students in a form.
The form can be used to create or edit a class. Also students can be added to that class. To reduce the effort needed to enter students, I would like to add a multi-select that shows the entries from the students-table. But since the number of students is expected to be large, I would like to filter this multi-select.
I checked this question on filtering lists and the sample app "Project List. I understand that the standard workflow with a table would be to bind the value of a search box to the #datasources.STUDENTS.query.filters.email._contains and set the tables datasource property to STUDENTS
But, as I understand it, a multi-select element's value property must be bound to #datasource.item.students and its datasource property must be CLASS in order for the auto-saving to work.
Hence I wonder whether it is possible to filter a multi-select element.
I don't see the problem, but I think I see a misunderstanding.
You said: "I understand that the standard workflow with a table would be to bind the value of a search box to the #datasources.STUDENTS.query.filters.email._contains"
You need to bind the OPTIONS (not value) to the datasource query, as it is the options that will draw its records from the #datasources.Students.query datasource.
You can then set the VALUE of the multi-select widget to #datasource.item.students (where you want selected values from the student query options to be saved).
You will also need to set the NAMES property (since the options are likely student records). Names will be the Student datasource projection of whatever string field you want to appear in the options list.

Database design for unknown fields

I am trying to make form builder in android. I have a real problem at designing database. In this application User first drags the required fields to the screen and change the labels of fields. The fields Contains:
CheckBox
RadioButton
TeXtBox
PlainText
This is my mockup:
I have real problem in designing database.I need a help to accomplish it.
Any Links to the tutorials or ER Diagrams will be really appreciated.
In this application user will drag his required fields to the screen as shown in mock up. Suppose when user drags on checkbox icon then the Editable Checkbox label and editable options will appear in the screen. Then Form builder names the label according to his requirements and options also. In this way he first builds the form .
That's what I created in 10 minutes, hope it helps.
TB_FieldType //field type
UUID_Type,
Type_Name, (Checkbox, RadioButton, Textbox, PlainText, Password, DropdownSelect...)
TB_FieldRule //Table field rule
UUID_Rule,
Rule (numeric only, not null...)
TB_UserTable //Save user designed thrir own table
UUID_Table,
Table_Name, (Designed table name)
TB_UserTable_Field //Designed table field detail
UUID_TableField,
UUID_Table,
UUID_Type,
UUID_GroupID, (can be null if field is single type*)
UUID_Rule,
Field_Name, (Display name)
Field_Length,
TB_Group //(for field(s) in multi type*, like RadioButton, DropwodnSelect... )
UUID,
GroupID,
GroupData,
I would create a table for storing the field definitions with fields like this:
survey_id (reference to the survey which the field belongs to)
field_id (unique id of the field)
field_type (checkbox, radio, plain etc.)
field_label
field_data (additional information if required, e.g. selection options for radio - dependent on type)
field_index (defines the order of fields)
... any additional field you may need
From this data, you can dynamically build your GUI.
And you will need another table for storing the answers (if it is in scope of your app):
field_id (reference to the former table)
value (entered by the user)
...user_id, timestamp etc. according to your needs

Access Bound Combobox with lookup Field?

I have a table. Table1. Table1.[Field1] displays a lookup field taken from Table2.[Field2].
In my Form I have two comboboxes. Combobox1 is bound to Table1.[Field2].
Remember.... Table1.[Field1] is displaying the "looked up value".
What I want to do is to use a bound Combobox2 so that it displays the looked up value (I have achieved this)... and then, when I change that value using the drop down list in Combobox2 to another value, it changes the record displayed in all my other controls, including Combobox1.
I'm not too sure what settings to use in my properties. Would anyone know how to achieve the above?
Thanks
(MS Access 2010)(Windows 7 Pro)

Lookup field appears as numerical values instead of text on Access report

I am trying to create a report putting a field called contact which has the name of a person. This name is linked directly to another table where I keep all the contacts.
For some strange reason, when I include this name (which in query view displays as the name of the contact), instead of the name appearing, the unique ID number is shown on my report.
As mentioned in the article cited in the above comment, you can use a Combo Box control on your report to do the lookup for you. To see how this can be done, create a new report based on the table containing the lookup field, then drag and drop that field onto the report. That will create a Combo Box control with properties that look something like this:
Row Source: SELECT [Clients].[ID], [Clients].[LastName] FROM Clients;
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
You could use a similar Combo Box control on your actual report to display the client's name rather than their numeric ID value.
Another alternative would be to change the Control Source of the report's Text Box control to have it do a DLookUp() on the table. If the lookup field is named [client] then changing the Control Source of the Text Box to something like
=DLookUp("LastName","Clients","ID=" & [client])
would also work.
I wanted to add to the great answer by Gord:
When using a "web" database (started in Access 2007 I think), you cannot change a report's fields to ComboBox style, nor can you use DLookUp(). (web databases lack a ton of features)
The workaround for this, if you want to create a Web-Report that uses lookup fields, is to create a Web-Query first based on your Web-Table (all the Web-* stuff has a www planet icon over the logo, if you create a new Web-DB in Access 2007+ you'll see what I mean)
So, instead of Table -> Report, you'll have to do W-Table -> W-Query -> W-Report.
Then, the only thing you need to customize to get the data right is the W-Query. Start by trying to reproduce the look in the query to match what you want users to see in the report. Note that here in the query, lookups will work fine (instead of the unique ID's, you get field names like you want). However, this will not carry over to the report. To do that, you gotta get the actual text field name you want into the query:
You should already have one table in your query; start by adding the table that your first lookup field points to. For example, the table I want to print is called Stock_Boards, and it has a lookup field called PCBID_lookup that points to the table Stock_PCBs.
Since you're using lookup fields, there should already be a relationship line between the two tables when you add the second one. If there isn't, something has gone horribly wrong.
Now, see how that line connects two fields on the two different tables? For example, I've got my PCBID_lookup field on my Stock_Boards table, which connects to the ID field on my Stock_PCBs table. If I created a report from this now, PCBID_lookup would be a number, a number that correlates to the ID of a record on Stock_PCBs.
To fix it, I will add the name field I want to show up on the report. In my example, that happens to be a Part Number, rather than the ID. I add the PartNumber field from my Stock_PCBs table to the query, and remove the PCBID_lookup field of the Stock_Boards table from my query.
Since PartNumber is what I want to show up on my report, it effectively replaces the original field (PCBID_lookup)
Repeat for all lookup fields you want in your report.
I had 1 more: I removed the Status field of the Stock_Boards table (which was an ID/Lookup) and added the 'Status' field from the Status table (which was the actual text name)
When finished, your query should look exactly how you want the data to appear, without any special tricks or asking Access to do something unnatural. Save your query, and create a web-report from it. Done!

adding field to the combo box in assest depreciation profile form

i am new to ax2012. I have a doubt in asset depreciation profile form.There is combo box called period frequency in that, i need to add a field called monthly. Can any one help me out ?
I have tried out by creating base enum for monthly filed but i didn't get the output required.
This field is an Enum of type AssetAccrualFiscal, therefore you need to add a monthly element to this AssetAccrualFiscal in the AOT.
Beware however, the field is controlled by an edit method, and changing the field triggers some business logic.
This can be found in the table method accrualFiscal() on the table AssetDepreciationProfile. You may need to decide which part of the existing logic needs to consider your new enum element when it is selected.
See my comment, but basically you need to find out which base enum the combo box uses (supposing it is an enum combo box) and add a new element "monthly" to that enum.
If it is a standard enum, please leave a gap between the last enum element index and the index of your new element. This leaves room for new elements from Microsoft and enables easier upgrades.
Did some digging, in AX 2012 R2 there already is an element "monthly" for the period frequency combo box. Please take a look at enum "AssetAccrualCalendar" and method "accrualCalendar" on table AssetDepreciationProfile.

Resources